mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-11-04 13:48:30 +00:00
Compare commits
268
Commits
v2.60test9
...
v2.66test2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b75c1e61f | ||
|
|
293fd0f700 | ||
|
|
c1be917782 | ||
|
|
bb86e858b6 | ||
|
|
8445f5d2e2 | ||
|
|
72c9c3b11b | ||
|
|
6e3dba3fde | ||
|
|
7558ecd9ac | ||
|
|
1f776932a1 | ||
|
|
4820dce97a | ||
|
|
f8abe0c566 | ||
|
|
9def963c65 | ||
|
|
990123a937 | ||
|
|
1d6c639310 | ||
|
|
429798fd08 | ||
|
|
b5a8dd1dec | ||
|
|
95a0bd3701 | ||
|
|
8ff556739e | ||
|
|
496787677e | ||
|
|
e1ff419cf9 | ||
|
|
ee86ce68fc | ||
|
|
b75e936372 | ||
|
|
aa79235194 | ||
|
|
7c305be1bd | ||
|
|
f7fe362721 | ||
|
|
36bec089f7 | ||
|
|
45dd1fece4 | ||
|
|
29d28dda95 | ||
|
|
421594f83d | ||
|
|
d89fb4ed4f | ||
|
|
295a54eed3 | ||
|
|
5c0bd5b112 | ||
|
|
86e3b9a026 | ||
|
|
2f38141f43 | ||
|
|
8273ea5a19 | ||
|
|
4f7b304f53 | ||
|
|
8e4b87918f | ||
|
|
83b2198e86 | ||
|
|
d1a5975f9b | ||
|
|
52002051ad | ||
|
|
b191a77901 | ||
|
|
23780dd577 | ||
|
|
d1e9a582ad | ||
|
|
819ff4dd0f | ||
|
|
de604c18a0 | ||
|
|
be6cfb42ab | ||
|
|
2022310f95 | ||
|
|
657ed09693 | ||
|
|
c99df938d7 | ||
|
|
cf568a3726 | ||
|
|
e4807d8bb2 | ||
|
|
35239a302a | ||
|
|
db3946c358 | ||
|
|
0d28af84d0 | ||
|
|
42698cb7ab | ||
|
|
1d860415f2 | ||
|
|
289a253569 | ||
|
|
faafb3f7b7 | ||
|
|
2b127a1eab | ||
|
|
dfb23b3f77 | ||
|
|
b269221c00 | ||
|
|
8b46061e73 | ||
|
|
4d0f5b4c44 | ||
|
|
1dedeb87cc | ||
|
|
79cfefd856 | ||
|
|
0c0d4793ac | ||
|
|
12d71ed28c | ||
|
|
9fed0f71c2 | ||
|
|
2e34ac1403 | ||
|
|
bc54ae392b | ||
|
|
00acd06340 | ||
|
|
476e4a03c1 | ||
|
|
5f11b3e5e0 | ||
|
|
3169daad46 | ||
|
|
fd05f12790 | ||
|
|
ad094275b0 | ||
|
|
c740e4f342 | ||
|
|
132255b5da | ||
|
|
c4c0488ac6 | ||
|
|
a2ce6fcc91 | ||
|
|
12090548d2 | ||
|
|
8223cb15e7 | ||
|
|
4ba9b38cc5 | ||
|
|
42243214b5 | ||
|
|
23245c0cb2 | ||
|
|
b271446f82 | ||
|
|
611ebc5f1e | ||
|
|
be0f45cdbc | ||
|
|
9b40cbf587 | ||
|
|
c4a7f90ebb | ||
|
|
9609baee41 | ||
|
|
395eb71931 | ||
|
|
8bc4cecee6 | ||
|
|
6b617c0d15 | ||
|
|
55d290a3bf | ||
|
|
e17b4b3871 | ||
|
|
236e072cab | ||
|
|
05ff1ed7cc | ||
|
|
2b5bae9a8f | ||
|
|
39f1b8e73d | ||
|
|
af576b56c2 | ||
|
|
54dd393f39 | ||
|
|
4ce4f3779b | ||
|
|
8b3ae2fd43 | ||
|
|
ed55cb66e6 | ||
|
|
2cd9a0de1f | ||
|
|
c514ab9907 | ||
|
|
078a630bba | ||
|
|
43c271b07c | ||
|
|
24ce681e51 | ||
|
|
5ae34bf3c8 | ||
|
|
51931b888a | ||
|
|
9f7f3b1216 | ||
|
|
97c83bb05b | ||
|
|
8767ceecd4 | ||
|
|
18c63eff8f | ||
|
|
c64b7f6a78 | ||
|
|
068b4b51e3 | ||
|
|
919dd7cf14 | ||
|
|
f632e56793 | ||
|
|
2021c66251 | ||
|
|
8358e0f4b2 | ||
|
|
7f61b3ad59 | ||
|
|
a9ab732e35 | ||
|
|
11263a462c | ||
|
|
231d061b45 | ||
|
|
cdbee9a40b | ||
|
|
7b4ad2eb34 | ||
|
|
19d69be220 | ||
|
|
04363607aa | ||
|
|
dcffad2a86 | ||
|
|
6a69ab5ebd | ||
|
|
fc92ead0dd | ||
|
|
61ce600b20 | ||
|
|
7a14dfebbb | ||
|
|
42fb8153ba | ||
|
|
6f13e53886 | ||
|
|
d1c759c5c1 | ||
|
|
e46164e0bd | ||
|
|
7389ce7ff5 | ||
|
|
2f77797b17 | ||
|
|
9380ba70d6 | ||
|
|
1023dcbc9e | ||
|
|
83e854e359 | ||
|
|
50303b19d8 | ||
|
|
89382bacaa | ||
|
|
6c559c34df | ||
|
|
adaa6888dd | ||
|
|
a813111379 | ||
|
|
18f0fb050b | ||
|
|
05e92e5afe | ||
|
|
4723d49dad | ||
|
|
fbbc14541a | ||
|
|
5ef33279f2 | ||
|
|
1e02a85970 | ||
|
|
0e88d53faa | ||
|
|
01d1b8ddf2 | ||
|
|
c8257540bc | ||
|
|
2240704863 | ||
|
|
e8ca69ea16 | ||
|
|
da632e7cc1 | ||
|
|
30cd96663f | ||
|
|
7dbe98147d | ||
|
|
5d71d83420 | ||
|
|
38a59a9ff7 | ||
|
|
4b028ad612 | ||
|
|
442560beb4 | ||
|
|
7d2b5c9583 | ||
|
|
29689cfa5a | ||
|
|
52d4abf2f9 | ||
|
|
a953096485 | ||
|
|
884a6dfe6d | ||
|
|
0068301d24 | ||
|
|
353ae4d270 | ||
|
|
e759d426fa | ||
|
|
40ef23b547 | ||
|
|
f5e8562f96 | ||
|
|
1567feae3c | ||
|
|
daf061c9de | ||
|
|
d0e2c6c9ab | ||
|
|
8643ec7fea | ||
|
|
5cfea3d402 | ||
|
|
6c8f21e4a4 | ||
|
|
1d0f91c4a9 | ||
|
|
2a82db4caf | ||
|
|
dd88c17f15 | ||
|
|
8b37270410 | ||
|
|
760169fc43 | ||
|
|
7023e38294 | ||
|
|
a7cf58cc47 | ||
|
|
e25d1a2ea2 | ||
|
|
70969c1757 | ||
|
|
3803437dcc | ||
|
|
eabc6dd76a | ||
|
|
e28d2e2b77 | ||
|
|
96fafe2ed6 | ||
|
|
c81d390f84 | ||
|
|
08456c61f6 | ||
|
|
bc26f9a03f | ||
|
|
6ffeff86be | ||
|
|
f444cddbaf | ||
|
|
d13191a46c | ||
|
|
801ca9a7b7 | ||
|
|
df66e341de | ||
|
|
71ee7ee254 | ||
|
|
a156cae901 | ||
|
|
22b135a116 | ||
|
|
0f08983d85 | ||
|
|
e3e86343fc | ||
|
|
7b6dd880f7 | ||
|
|
b7f4020133 | ||
|
|
c46c7c7584 | ||
|
|
552af8b988 | ||
|
|
4f8ff361dc | ||
|
|
0010b47439 | ||
|
|
4b86b65d07 | ||
|
|
248489401a | ||
|
|
bc5992daf6 | ||
|
|
fdacfb0119 | ||
|
|
0d5d35d052 | ||
|
|
843c96b4b3 | ||
|
|
58dc02ebf2 | ||
|
|
c239f7de25 | ||
|
|
ac8540c3c5 | ||
|
|
22d904db95 | ||
|
|
741c2952d4 | ||
|
|
96f6979c4f | ||
|
|
c5379c1ab6 | ||
|
|
a4a5205fd7 | ||
|
|
c5ad4e7998 | ||
|
|
270dc2e199 | ||
|
|
948a0b6e81 | ||
|
|
87b8ecb13a | ||
|
|
e44ddcac63 | ||
|
|
00e9ad5217 | ||
|
|
96c3879bed | ||
|
|
57f460de2f | ||
|
|
6caacacf6d | ||
|
|
60ac5af682 | ||
|
|
caa94380ac | ||
|
|
0793380b40 | ||
|
|
1adadf585d | ||
|
|
e5ffdb9c77 | ||
|
|
6da5201092 | ||
|
|
b36ae19434 | ||
|
|
2307eac613 | ||
|
|
127ea40ae7 | ||
|
|
6aef600d48 | ||
|
|
98d76a0326 | ||
|
|
6ea6dcf05b | ||
|
|
627797800d | ||
|
|
c6cc03ed0c | ||
|
|
3d7b550f52 | ||
|
|
751d6f4ae6 | ||
|
|
a5c72ab51d | ||
|
|
9bbc88762b | ||
|
|
ceae00dddf | ||
|
|
3634c54e8d | ||
|
|
d74942a03d | ||
|
|
70c5e3e076 | ||
|
|
4cb1b32009 | ||
|
|
3268e90f5e | ||
|
|
e98170816a | ||
|
|
52b92f4db8 | ||
|
|
a2761754da | ||
|
|
805a11345c | ||
|
|
1ab62aec37 | ||
|
|
be2daf4ad5 |
No files matched your search
+13
@@ -0,0 +1,13 @@
|
|||||||
|
src/*.o
|
||||||
|
src/*.mo
|
||||||
|
src/dnsmasq.pot
|
||||||
|
src/dnsmasq
|
||||||
|
src/.configured
|
||||||
|
contrib/wrt/dhcp_lease_time
|
||||||
|
contrib/wrt/dhcp_release
|
||||||
|
debian/base/
|
||||||
|
debian/daemon/
|
||||||
|
debian/files
|
||||||
|
debian/substvars
|
||||||
|
debian/utils-substvars
|
||||||
|
debian/utils/
|
||||||
@@ -1,3 +1,267 @@
|
|||||||
|
version 2.65
|
||||||
|
Fix regression which broke forwarding of queries sent via
|
||||||
|
TCP which are not for A and AAAA and which were directed to
|
||||||
|
non-default servers. Thanks to Niax for the bug report.
|
||||||
|
|
||||||
|
Fix failure to build with DHCP support excluded. Thanks to
|
||||||
|
Gustavo Zacarias for the patch.
|
||||||
|
|
||||||
|
Fix nasty regression in 2.64 which completely broke cacheing.
|
||||||
|
|
||||||
|
|
||||||
|
version 2.64
|
||||||
|
Handle DHCP FQDN options with all flag bits zero and
|
||||||
|
--dhcp-client-update set. Thanks to Bernd Krumbroeck for
|
||||||
|
spotting the problem.
|
||||||
|
|
||||||
|
Finesse the check for /etc/hosts names which conflict with
|
||||||
|
DHCP names. Previously a name/address pair in /etc/hosts
|
||||||
|
which didn't match the name/address of a DHCP lease would
|
||||||
|
generate a warning. Now that only happesn if there is not
|
||||||
|
also a match. This allows multiple addresses for a name in
|
||||||
|
/etc/hosts with one of them assigned via DHCP.
|
||||||
|
|
||||||
|
Fix broken vendor-option processing for BOOTP. Thanks to
|
||||||
|
Hans-Joachim Baader for the bug report.
|
||||||
|
|
||||||
|
Don't report spurious netlink errors, regression in
|
||||||
|
2.63. Thanks to Vladislav Grishenko for the patch.
|
||||||
|
|
||||||
|
Flag DHCP or DHCPv6 in starup logging. Thanks to
|
||||||
|
Vladislav Grishenko for the patch.
|
||||||
|
|
||||||
|
Add SetServersEx method in DBus interface. Thanks to Dan
|
||||||
|
Williams for the patch.
|
||||||
|
|
||||||
|
Add SetDomainServers method in DBus interface. Thanks to
|
||||||
|
Roy Marples for the patch.
|
||||||
|
|
||||||
|
Fix build with later Lua libraries. Thansk to Cristian
|
||||||
|
Rodriguez for the patch.
|
||||||
|
|
||||||
|
Add --max-cache-ttl option. Thanks to Dennis Kaarsemaker
|
||||||
|
for the patch.
|
||||||
|
|
||||||
|
Fix breakage of --host-record parsing, resulting in
|
||||||
|
infinte loop at startup. Regression in 2.63. Thanks to
|
||||||
|
Haim Gelfenbeyn for spotting this.
|
||||||
|
|
||||||
|
Set SO_REUSEADDRESS and SO_V6ONLY options on the DHCPv6
|
||||||
|
socket, this allows multiple instances of dnsmasq on a
|
||||||
|
single machine, in the same way as for DHCPv4. Thanks to
|
||||||
|
Gene Czarcinski and Vladislav Grishenko for work on this.
|
||||||
|
|
||||||
|
Fix DHCPv6 to do access control correctly when it's
|
||||||
|
configured with --listen-address. Thanks to
|
||||||
|
Gene Czarcinski for sorting this out.
|
||||||
|
|
||||||
|
Add a "wildcard" dhcp-range which works for any IPv6
|
||||||
|
subnet, --dhcp-range=::,static Useful for Stateless
|
||||||
|
DHCPv6. Thanks to Vladislav Grishenko for the patch.
|
||||||
|
|
||||||
|
Don't include lease-time in DHCPACK replies to DHCPINFORM
|
||||||
|
queries, since RFC-2131 says we shouldn't. Thanks to
|
||||||
|
Wouter Ibens for pointing this out.
|
||||||
|
|
||||||
|
Makefile tweak to do dependency checking on header files.
|
||||||
|
Thanks to Johan Peeters for the patch.
|
||||||
|
|
||||||
|
Check interface for outgoing unsolicited router
|
||||||
|
advertisements, rather than relying on interface address
|
||||||
|
configuration. Thanks to Gene Czarinski for the patch.
|
||||||
|
|
||||||
|
Handle better attempts to transmit on interfaces which are
|
||||||
|
still doing DAD, and specifically do not just transmit
|
||||||
|
without setting source address and interface, since this
|
||||||
|
can cause very puzzling effects when a router
|
||||||
|
advertisement goes astray. Thanks again to Gene Czarinski.
|
||||||
|
|
||||||
|
Get RA timers right when there is more than one
|
||||||
|
dhcp-range on a subnet.
|
||||||
|
|
||||||
|
|
||||||
|
version 2.63
|
||||||
|
Do duplicate dhcp-host address check in --test mode.
|
||||||
|
|
||||||
|
Check that tftp-root directories are accessible before
|
||||||
|
start-up. Thanks to Daniel Veillard for the initial patch.
|
||||||
|
|
||||||
|
Allow more than one --tfp-root flag. The per-interface
|
||||||
|
stuff is pointless without that.
|
||||||
|
|
||||||
|
Add --bind-dynamic. A hybrid mode between the default and
|
||||||
|
--bind-interfaces which copes with dynamically created
|
||||||
|
interfaces.
|
||||||
|
|
||||||
|
A couple of fixes to the build system for Android. Thanks
|
||||||
|
to Metin Kaya for the patches.
|
||||||
|
|
||||||
|
Remove the interface:<interface> argument in --dhcp-range, and
|
||||||
|
the interface argument to --enable-tftp. These were a
|
||||||
|
still-born attempt to allow automatic isolated
|
||||||
|
configuration by libvirt, but have never (to my knowledge)
|
||||||
|
been used, had very strange semantics, and have been
|
||||||
|
superceded by other mechanisms.
|
||||||
|
|
||||||
|
Fixed bug logging filenames when duplicate dhcp-host
|
||||||
|
addresses are found. Thanks to John Hanks for the patch.
|
||||||
|
|
||||||
|
Fix regression in 2.61 which broke caching of CNAME
|
||||||
|
chains. Thanks to Atul Gupta for the bug report.
|
||||||
|
|
||||||
|
Allow the target of a --cname flag to be another --cname.
|
||||||
|
|
||||||
|
Teach DHCPv6 about the RFC 4242 information-refresh-time
|
||||||
|
option, and add parsing if the minutes, hours and days
|
||||||
|
format for options. Thanks to Francois-Xavier Le Bail for
|
||||||
|
the suggestion.
|
||||||
|
|
||||||
|
Allow "w" (for week) as multiplier in lease times, as well
|
||||||
|
as seconds, minutes, hours and days. Álvaro Gámez Machado
|
||||||
|
spotted the ommission.
|
||||||
|
|
||||||
|
Update French translation. Thanks to Gildas Le Nadan.
|
||||||
|
|
||||||
|
Allow a DBus service name to be given with --enable-dbus
|
||||||
|
which overrides the default,
|
||||||
|
uk.org.thekelleys.dnsmasq. Thanks to Mathieu
|
||||||
|
Trudel-Lapierre for the patch.
|
||||||
|
|
||||||
|
Set the "prefix on-link" bit in Router
|
||||||
|
Advertisements. Thanks to Gui Iribarren for the patch.
|
||||||
|
|
||||||
|
|
||||||
|
version 2.62
|
||||||
|
Update German translation. Thanks to Conrad Kostecki.
|
||||||
|
|
||||||
|
Cope with router-solict packets wich don't have a valid
|
||||||
|
source address. Thanks to Vladislav Grishenko for the patch.
|
||||||
|
|
||||||
|
Fixed bug which caused missing periodic router
|
||||||
|
advertisements with some configurations. Thanks to
|
||||||
|
Vladislav Grishenko for the patch.
|
||||||
|
|
||||||
|
Fixed bug which broke DHCPv6/RA with prefix lengths
|
||||||
|
which are not divisible by 8. Thanks to Andre Coetzee
|
||||||
|
for spotting this.
|
||||||
|
|
||||||
|
Fix non-response to router-solicitations when
|
||||||
|
router-advertisement configured, but DHCPv6 not
|
||||||
|
configured. Thanks to Marien Zwart for the patch.
|
||||||
|
|
||||||
|
Add --dns-rr, to allow arbitrary DNS resource records.
|
||||||
|
|
||||||
|
Fixed bug which broke RA scheduling when an interface had
|
||||||
|
two addresses in the same network. Thanks to Jim Bos for
|
||||||
|
his help nailing this.
|
||||||
|
|
||||||
|
version 2.61
|
||||||
|
Re-write interface discovery code on *BSD to use
|
||||||
|
getifaddrs. This is more portable, more straightforward,
|
||||||
|
and allows us to find the prefix length for IPv6
|
||||||
|
addresses.
|
||||||
|
|
||||||
|
Add ra-names, ra-stateless and slaac keywords for DHCPv6.
|
||||||
|
Dnsmasq can now synthesise AAAA records for dual-stack
|
||||||
|
hosts which get IPv6 addresses via SLAAC. It is also now
|
||||||
|
possible to use SLAAC and stateless DHCPv6, and to
|
||||||
|
tell clients to use SLAAC addresses as well as DHCP ones.
|
||||||
|
Thanks to Dave Taht for help with this.
|
||||||
|
|
||||||
|
Add --dhcp-duid to allow DUID-EN uids to be used.
|
||||||
|
|
||||||
|
Explicity send DHCPv6 replies to the correct port, instead
|
||||||
|
of relying on clients to send requests with the correct
|
||||||
|
source address, since at least one client in the wild gets
|
||||||
|
this wrong. Thanks to Conrad Kostecki for help tracking
|
||||||
|
this down.
|
||||||
|
|
||||||
|
Send a preference value of 255 in DHCPv6 replies when
|
||||||
|
--dhcp-authoritative is in effect. This tells clients not
|
||||||
|
to wait around for other DHCP servers.
|
||||||
|
|
||||||
|
Better logging of DHCPv6 options.
|
||||||
|
|
||||||
|
Add --host-record. Thanks to Rob Zwissler for the
|
||||||
|
suggestion.
|
||||||
|
|
||||||
|
Invoke the DHCP script with action "tftp" when a TFTP file
|
||||||
|
transfer completes. The size of the file, address to which
|
||||||
|
it was sent and complete pathname are supplied. Note that
|
||||||
|
version 2.60 introduced some script incompatibilties
|
||||||
|
associated with DHCPv6, and this is a further change. To
|
||||||
|
be safe, scripts should ignore unknown actions, and if
|
||||||
|
not IPv6-aware, should exit if the environment
|
||||||
|
variable DNSMASQ_IAID is set. The use-case for this is
|
||||||
|
to track netboot/install. Suggestion from Shantanu
|
||||||
|
Gadgil.
|
||||||
|
|
||||||
|
Update contrib/port-forward/dnsmasq-portforward to reflect
|
||||||
|
the above.
|
||||||
|
|
||||||
|
Set the environment variable DNSMASQ_LOG_DHCP when running
|
||||||
|
the script id --log-dhcp is in effect, so that script can
|
||||||
|
taylor their logging verbosity. Suggestion from Malte
|
||||||
|
Forkel.
|
||||||
|
|
||||||
|
Arrange that addresses specified with --listen-address
|
||||||
|
work even if there is no interface carrying the
|
||||||
|
address. This is chiefly useful for IPv4 loopback
|
||||||
|
addresses, where any address in 127.0.0.0/8 is a valid
|
||||||
|
loopback address, but normally only 127.0.0.1 appears on
|
||||||
|
the lo interface. Thanks to Mathieu Trudel-Lapierre for
|
||||||
|
the idea and initial patch.
|
||||||
|
|
||||||
|
Fix crash, introduced in 2.60, when a DHCPINFORM is
|
||||||
|
received from a network which has no valid dhcp-range.
|
||||||
|
Thanks to Stephane Glondu for the bug report.
|
||||||
|
|
||||||
|
Add a new DHCP lease time keyword, "deprecated" for
|
||||||
|
--dhcp-range. This is only valid for IPv6, and sets the
|
||||||
|
preffered lease time for both DHCP and RA to zero. The
|
||||||
|
effect is that clients can continue to use the address
|
||||||
|
for existing connections, but new connections will use
|
||||||
|
other addresses, if they exist. This makes hitless
|
||||||
|
renumbering at least possible.
|
||||||
|
|
||||||
|
Fix bug in address6_available() which caused DHCPv6 lease
|
||||||
|
aquisition to fail if more than one dhcp-range in use.
|
||||||
|
|
||||||
|
Provide RDNSS and DNSSL data in router advertisements,
|
||||||
|
using the settings provided for DHCP options
|
||||||
|
option6:domain-search and option6:dns-server.
|
||||||
|
|
||||||
|
Tweak logo/favicon.ico to add some transparency. Thanks to
|
||||||
|
SamLT for work on this.
|
||||||
|
|
||||||
|
Don't cache data from non-recursive nameservers, since it
|
||||||
|
may erroneously look like a valid CNAME to a non-exitant
|
||||||
|
name. Thanks to Ben Winslow for finding this.
|
||||||
|
|
||||||
|
Call SO_BINDTODEVICE on the DHCP socket(s) when doing DHCP
|
||||||
|
on exactly one interface and --bind-interfaces is set. This
|
||||||
|
makes the OpenStack use-case of one dnsmasq per virtual
|
||||||
|
interface work. This is only available on Linux; it's not
|
||||||
|
supported on other platforms. Thanks to Vishvananda Ishaya
|
||||||
|
and the OpenStack team for the suggestion.
|
||||||
|
|
||||||
|
Updated French translation. Thanks to Gildas Le Nadan.
|
||||||
|
|
||||||
|
Give correct from-cache answers to explict CNAME queries.
|
||||||
|
Thanks to Rob Zwissler for spotting this.
|
||||||
|
|
||||||
|
Add --tftp-lowercase option. Thanks to Oliver Rath for the
|
||||||
|
patch.
|
||||||
|
|
||||||
|
Ensure that the DBus DhcpLeaseUpdated events are generated
|
||||||
|
when a lease goes through INIT_REBOOT state, even if the
|
||||||
|
dhcp-script is not in use. Thanks to Antoaneta-Ecaterina
|
||||||
|
Ene for the patch.
|
||||||
|
|
||||||
|
Fix failure of TFTP over IPv4 on OpenBSD platform. Thanks
|
||||||
|
to Brad Smith for spotting this.
|
||||||
|
|
||||||
|
|
||||||
version 2.60
|
version 2.60
|
||||||
Fix compilation problem in Mac OS X Lion. Thanks to Olaf
|
Fix compilation problem in Mac OS X Lion. Thanks to Olaf
|
||||||
Flebbe for the patch.
|
Flebbe for the patch.
|
||||||
@@ -29,7 +293,58 @@ version 2.60
|
|||||||
Determine VERSION automatically based on git magic:
|
Determine VERSION automatically based on git magic:
|
||||||
release tags or hash values.
|
release tags or hash values.
|
||||||
|
|
||||||
|
Improve start-up speed when reading large hosts files
|
||||||
|
containing many distinct addresses.
|
||||||
|
|
||||||
|
Fix problem if dnsmasq is started without the stdin,
|
||||||
|
stdout and stderr file descriptors open. This can manifest
|
||||||
|
itself as 100% CPU use. Thanks to Chris Moore for finding
|
||||||
|
this.
|
||||||
|
|
||||||
|
Fix shell-scripting bug in bld/pkg-wrapper. Thanks to
|
||||||
|
Mark Mitchell for the patch.
|
||||||
|
|
||||||
|
Allow the TFP server or boot server in --pxe-service, to
|
||||||
|
be a domain name instead of an IP address. This allows for
|
||||||
|
round-robin to multiple servers, in the same way as
|
||||||
|
--dhcp-boot. A good suggestion from Cristiano Cumer.
|
||||||
|
|
||||||
|
Support BUILDDIR variable in the Makefile. Allows builds
|
||||||
|
for multiple archs from the same source tree with eg.
|
||||||
|
make BUILDDIR=linux (relative to dnsmasq tree)
|
||||||
|
make BUILDDIR=/tmp/openbsd (absolute path)
|
||||||
|
If BUILDDIR is not set, compilation happens in the src
|
||||||
|
directory, as before. Suggestion from Mark Mitchell.
|
||||||
|
|
||||||
|
Support DHCPv6. Support is there for the sort of things
|
||||||
|
the existing v4 server does, including tags, options,
|
||||||
|
static addresses and relay support. Missing is prefix
|
||||||
|
delegation, which is probably not required in the dnsmasq
|
||||||
|
niche, and an easy way to accept prefix delegations from
|
||||||
|
an upstream DHCPv6 server, which is. Future plans include
|
||||||
|
support for DHCPv6 router option and MAC address option
|
||||||
|
(to make selecting clients by MAC address work like IPv4).
|
||||||
|
These will be added as the standards mature.
|
||||||
|
This code has been tested, but this is the first release,
|
||||||
|
so don't bet the farm on it just yet. Many thanks to all
|
||||||
|
testers who have got it this far.
|
||||||
|
|
||||||
|
Support IPv6 router advertisements. This is a
|
||||||
|
simple-minded implementation, aimed at providing the
|
||||||
|
vestigial RA needed to go alongside IPv6. Is picks up
|
||||||
|
configuration from the DHCPv6 conf, and should just need
|
||||||
|
enabling with --enable-ra.
|
||||||
|
|
||||||
|
Fix long-standing wrinkle with --localise-queries that
|
||||||
|
could result in wrong answers when DNS packets arrive
|
||||||
|
via an interface other than the expected one. Thanks to
|
||||||
|
Lorenzo Milesi and John Hanks for spotting this one.
|
||||||
|
|
||||||
|
Update French translation. Thanks to Gildas Le Nadan.
|
||||||
|
|
||||||
|
Update Polish translation. Thanks to Jan Psota.
|
||||||
|
|
||||||
|
|
||||||
version 2.59
|
version 2.59
|
||||||
Fix regression in 2.58 which caused failure to start up
|
Fix regression in 2.58 which caused failure to start up
|
||||||
with some combinations of dnsmasq config and IPv6 kernel
|
with some combinations of dnsmasq config and IPv6 kernel
|
||||||
@@ -126,7 +441,7 @@ version 2.58
|
|||||||
|
|
||||||
Fix regression in TFTP server on *BSD platforms introduced
|
Fix regression in TFTP server on *BSD platforms introduced
|
||||||
in version 2.56, due to confusion with sockaddr
|
in version 2.56, due to confusion with sockaddr
|
||||||
length. Many thanks to Loïc Pefferkorn for finding this.
|
length. Many thanks to Loic Pefferkorn for finding this.
|
||||||
|
|
||||||
Support scope-ids in IPv6 addresses of nameservers from
|
Support scope-ids in IPv6 addresses of nameservers from
|
||||||
/etc/resolv.conf and in --server options. Eg
|
/etc/resolv.conf and in --server options. Eg
|
||||||
|
|||||||
@@ -236,53 +236,70 @@ Q: What network types are supported by the DHCP server?
|
|||||||
A: Ethernet (and 802.11 wireless) are supported on all platforms. On
|
A: Ethernet (and 802.11 wireless) are supported on all platforms. On
|
||||||
Linux all network types (including FireWire) are supported.
|
Linux all network types (including FireWire) are supported.
|
||||||
|
|
||||||
Q: What is this strange "bind-interface" option?
|
Q: What are these strange "bind-interface" and "bind-dynamic" options?
|
||||||
|
|
||||||
A: The DNS spec says that the reply to a DNS query must come from the
|
A: Dnsmasq from v2.63 can operate in one of three different "networking
|
||||||
same address it was sent to. The traditional way to write an UDP
|
modes". This is unfortunate as it requires users configuring dnsmasq
|
||||||
server to do this is to find all of the addresses belonging to the
|
to take into account some rather bizzare contraints and select the
|
||||||
machine (ie all the interfaces on the machine) and then create a
|
mode which best fits the requirements of a particular installation.
|
||||||
socket for each interface which is bound to the address of the
|
The origin of these are deficiencies in the Unix networking
|
||||||
interface. Then when a packet is sent to address A, it is received
|
model and APIs and each mode has different advantages and
|
||||||
on the socket bound to address A and when the reply is also sent
|
problems. Just to add to the confusion, not all modes are available on
|
||||||
via that socket, the source address is set to A by the kernel and
|
all platforms (due the to lack of supporting network APIs).To further
|
||||||
everything works. This is the how dnsmasq works when
|
add to the confusion, the rules for the DHCP subsystem on dnsmasq are
|
||||||
"bind-interfaces" is set, with the obvious extension that is misses
|
different to the rules for the DNS and TFTP subsystems.
|
||||||
out creating sockets for some interfaces depending on the
|
|
||||||
--interface, --address and --except-interface flags. The
|
|
||||||
disadvantage of this approach is that it breaks if interfaces don't
|
|
||||||
exist or are not configured when the daemon starts and does the
|
|
||||||
socket creation step. In a hotplug-aware world this is a real
|
|
||||||
problem.
|
|
||||||
|
|
||||||
The alternative approach is to have only one socket, which is bound
|
The three modes are "wildcard", "bind-interfaces" and "bind-dynamic".
|
||||||
to the correct port and the wildcard IP address (0.0.0.0). That
|
|
||||||
socket will receive _all_ packets sent to port 53, no matter what
|
|
||||||
destination address they have. This solves the problem of
|
|
||||||
interfaces which are created or reconfigured after daemon
|
|
||||||
start-up. To make this work is more complicated because of the
|
|
||||||
"reply source address" problem. When a UDP packet is sent by a
|
|
||||||
socket bound to 0.0.0.0 its source address will be set to the
|
|
||||||
address of one of the machine's interfaces, but which one is not
|
|
||||||
determined and can vary depending on the OS being run. To get round
|
|
||||||
this it is neccessary to use a scary advanced API to determine the
|
|
||||||
address to which a query was sent, and force that to be the source
|
|
||||||
address in the reply. For IPv4 this stuff in non-portable and quite
|
|
||||||
often not even available (It's different between FreeBSD 5.x and
|
|
||||||
Linux, for instance, and FreeBSD 4.x, Linux 2.0.x and OpenBSD don't
|
|
||||||
have it at all.) Hence "bind-interfaces" has to always be available
|
|
||||||
as a fall back. For IPv6 the API is standard and universally
|
|
||||||
available.
|
|
||||||
|
|
||||||
It could be argued that if the --interface or --address flags are
|
In "wildcard" mode, dnsmasq binds the wildcard IP address (0.0.0.0 or
|
||||||
used then binding interfaces is more appropriate, but using
|
::). This allows it to recieve all the packets sent to the server on
|
||||||
wildcard binding means that dnsmasq will quite happily start up
|
the relevant port. Access control (--interface, --except-interface,
|
||||||
after being told to use interfaces which don't exist, but which are
|
--listen-address, etc) is implemented by dnsmasq: it queries the
|
||||||
created later. Wildcard binding breaks the scenario when dnsmasq is
|
kernel to determine the interface on which a packet was recieved and
|
||||||
listening on one interface and another server (most probably BIND)
|
the address to which it was sent, and applies the configured
|
||||||
is listening on another. It's not possible for BIND to bind to an
|
rules. Wildcard mode is the default if neither of the other modes are
|
||||||
(address,port) pair when dnsmasq has bound (wildcard,port), hence
|
specified.
|
||||||
the ability to explicitly turn off wildcard binding.
|
|
||||||
|
In "bind-interfaces" mode, dnsmasq runs through all the network
|
||||||
|
interfaces available when it starts, finds the set of IP addresses on
|
||||||
|
those interfaces, filters that set using the access control
|
||||||
|
configuration, and then binds the set of IP addresses. Only packets
|
||||||
|
sent to the allowed addresses are delivered by the kernel to dnsmasq.
|
||||||
|
|
||||||
|
In "bind-dynamic" mode, access control filtering is done both by
|
||||||
|
binding individual IP addresses, as for bind-interfaces, and by
|
||||||
|
inspecting individual packets on arrival as for wildcard mode. In
|
||||||
|
addition, dnsmasq notices when new interfaces appear or new addresses
|
||||||
|
appear on existing interfaces, and the resulting IP addresses are
|
||||||
|
bound automatically without having to restart dnsmasq.
|
||||||
|
|
||||||
|
The mode chosen has four different effects: co-existence with other
|
||||||
|
servers, semantics of --interface access control, effect of new
|
||||||
|
interfaces, and legality of --interface specifications for
|
||||||
|
non-existent inferfaces. We will deal with these in order.
|
||||||
|
|
||||||
|
A dnsmasq instance running in wildcard mode precludes a machine from
|
||||||
|
running a second instance of dnsmasq or any other DNS, TFTP or DHCP
|
||||||
|
server. Attempts to do so will fail with an "address in use" error.
|
||||||
|
Dnsmasq running in --bind-interfaces or bind-dynamic mode allow other
|
||||||
|
instances of dnsmasq or other servers, as long as no two servers are
|
||||||
|
configured to listen on the same interface address.
|
||||||
|
|
||||||
|
The semantics of --interface varies subtly between wildcard or
|
||||||
|
bind-dynamic mode and bind-interfaces mode. The situation where this
|
||||||
|
matters is a request which arrives via one interface (A), but with a
|
||||||
|
destination address of a second interface (B) and when dnsmasq is
|
||||||
|
configured to listen only on B. In wildcard or bind-dynamic mode, such
|
||||||
|
a request will be ignored, in bind-interfaces mode, it will be
|
||||||
|
accepted.
|
||||||
|
|
||||||
|
The creation of new network interfaces after dnsmasq starts is ignored
|
||||||
|
by dnsmasq when in --bind-interfaces mode. In wildcard or bind-dynamic
|
||||||
|
mode, such interfaces are handled normally.
|
||||||
|
|
||||||
|
A --interface specification for a non-existent interface is a fatal
|
||||||
|
error at start-up when in --bind-interfaces mode, by just generates a
|
||||||
|
warning in wildcard or bind-dynamic mode.
|
||||||
|
|
||||||
Q: Why doesn't Kerberos work/why can't I get sensible answers to
|
Q: Why doesn't Kerberos work/why can't I get sensible answers to
|
||||||
queries for SRV records.
|
queries for SRV records.
|
||||||
|
|||||||
@@ -13,92 +13,127 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
PREFIX = /usr/local
|
# NOTE: Building the i18n targets requires GNU-make
|
||||||
BINDIR = ${PREFIX}/sbin
|
|
||||||
MANDIR = ${PREFIX}/share/man
|
|
||||||
LOCALEDIR = ${PREFIX}/share/locale
|
|
||||||
|
|
||||||
PKG_CONFIG = pkg-config
|
|
||||||
INSTALL = install
|
|
||||||
MSGMERGE = msgmerge
|
|
||||||
MSGFMT = msgfmt
|
|
||||||
XGETTEXT = xgettext
|
|
||||||
|
|
||||||
CFLAGS = -Wall -W -O2
|
# Variables you may well want to override.
|
||||||
|
|
||||||
|
PREFIX = /usr/local
|
||||||
|
BINDIR = $(PREFIX)/sbin
|
||||||
|
MANDIR = $(PREFIX)/share/man
|
||||||
|
LOCALEDIR = $(PREFIX)/share/locale
|
||||||
|
BUILDDIR = $(SRC)
|
||||||
|
DESTDIR =
|
||||||
|
CFLAGS = -Wall -W -O2
|
||||||
|
LDFLAGS =
|
||||||
|
COPTS =
|
||||||
|
RPM_OPT_FLAGS =
|
||||||
|
LIBS =
|
||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
|
|
||||||
|
# Variables you might want to override.
|
||||||
|
|
||||||
|
PKG_CONFIG = pkg-config
|
||||||
|
INSTALL = install
|
||||||
|
MSGMERGE = msgmerge
|
||||||
|
MSGFMT = msgfmt
|
||||||
|
XGETTEXT = xgettext
|
||||||
|
|
||||||
SRC = src
|
SRC = src
|
||||||
PO = po
|
PO = po
|
||||||
MAN = man
|
MAN = man
|
||||||
|
|
||||||
DBUS_CFLAGS=`echo $(COPTS) | ../bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1`
|
#################################################################
|
||||||
DBUS_LIBS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1`
|
|
||||||
IDN_CFLAGS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn`
|
|
||||||
IDN_LIBS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn`
|
|
||||||
CT_CFLAGS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --cflags libnetfilter_conntrack`
|
|
||||||
CT_LIBS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
|
|
||||||
LUA_CFLAGS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.1`
|
|
||||||
LUA_LIBS= `echo $(COPTS) | ../bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.1`
|
|
||||||
SUNOS_LIBS= `if uname | grep SunOS 2>&1 >/dev/null; then echo -lsocket -lnsl -lposix4; fi`
|
|
||||||
VERSION= -DVERSION='\"`../bld/get-version`\"'
|
|
||||||
|
|
||||||
OBJS = cache.o rfc1035.o util.o option.o forward.o network.o \
|
# pmake way. (NB no spaces to keep gmake 3.82 happy)
|
||||||
|
top!=pwd
|
||||||
|
# GNU make way.
|
||||||
|
top?=$(CURDIR)
|
||||||
|
|
||||||
|
dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1`
|
||||||
|
dbus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1`
|
||||||
|
idn_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn`
|
||||||
|
idn_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn`
|
||||||
|
ct_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --cflags libnetfilter_conntrack`
|
||||||
|
ct_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
|
||||||
|
lua_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.1`
|
||||||
|
lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.1`
|
||||||
|
sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
|
||||||
|
version = -DVERSION='\"`$(top)/bld/get-version $(top)`\"'
|
||||||
|
|
||||||
|
objs = cache.o rfc1035.o util.o option.o forward.o network.o \
|
||||||
dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o \
|
dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o \
|
||||||
helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o
|
helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \
|
||||||
|
dhcp-common.o outpacket.o radv.o slaac.o auth.o
|
||||||
|
|
||||||
all :
|
hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
|
||||||
@cd $(SRC) && $(MAKE) \
|
dns-protocol.h radv-protocol.h
|
||||||
BUILD_CFLAGS="$(VERSION) $(DBUS_CFLAGS) $(IDN_CFLAGS) $(CT_CFLAGS) $(LUA_CFLAGS)" \
|
|
||||||
BUILD_LIBS="$(DBUS_LIBS) $(IDN_LIBS) $(CT_LIBS) $(LUA_LIBS) $(SUNOS_LIBS)" \
|
all : $(BUILDDIR)
|
||||||
-f ../Makefile dnsmasq
|
@cd $(BUILDDIR) && $(MAKE) \
|
||||||
|
top="$(top)" \
|
||||||
|
build_cflags="$(version) $(dbus_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags)" \
|
||||||
|
build_libs="$(dbus_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs)" \
|
||||||
|
-f $(top)/Makefile dnsmasq
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -f *~ $(SRC)/*.mo contrib/*/*~ */*~ $(SRC)/*.pot
|
rm -f *~ $(BUILDDIR)/*.mo contrib/*/*~ */*~ $(BUILDDIR)/*.pot
|
||||||
rm -f $(SRC)/*.o $(SRC)/dnsmasq.a $(SRC)/dnsmasq core */core
|
rm -f $(BUILDDIR)/.configured $(BUILDDIR)/*.o $(BUILDDIR)/dnsmasq.a $(BUILDDIR)/dnsmasq
|
||||||
|
rm -rf core */core
|
||||||
|
|
||||||
install : all install-common
|
install : all install-common
|
||||||
|
|
||||||
install-common :
|
install-common :
|
||||||
$(INSTALL) -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
|
$(INSTALL) -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
|
||||||
$(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8
|
$(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8
|
||||||
$(INSTALL) -m 755 $(SRC)/dnsmasq $(DESTDIR)$(BINDIR)
|
$(INSTALL) -m 755 $(BUILDDIR)/dnsmasq $(DESTDIR)$(BINDIR)
|
||||||
|
|
||||||
all-i18n :
|
all-i18n : $(BUILDDIR)
|
||||||
@cd $(SRC) && $(MAKE) \
|
@cd $(BUILDDIR) && $(MAKE) \
|
||||||
I18N=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
|
top="$(top)" \
|
||||||
BUILD_CFLAGS="$(VERSION) $(DBUS_CFLAGS) $(CT_CFLAGS) $(LUA_CFLAGS) `$(PKG_CONFIG) --cflags libidn`" \
|
i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
|
||||||
BUILD_LIBS="$(DBUS_LIBS) $(CT_LIBS) $(LUA_LIBS) $(SUNOS_LIBS) `$(PKG_CONFIG) --libs libidn`" \
|
build_cflags="$(version) $(dbus_cflags) $(ct_cflags) $(lua_cflags) `$(PKG_CONFIG) --cflags libidn`" \
|
||||||
-f ../Makefile dnsmasq
|
build_libs="$(dbus_libs) $(ct_libs) $(lua_libs) $(sunos_libs) `$(PKG_CONFIG) --libs libidn`" \
|
||||||
@cd $(PO); for f in *.po; do \
|
-f $(top)/Makefile dnsmasq
|
||||||
cd ../$(SRC) && $(MAKE) \
|
for f in `cd $(PO); echo *.po`; do \
|
||||||
-f ../Makefile $${f%.po}.mo; \
|
cd $(top) && cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile $${f%.po}.mo; \
|
||||||
done
|
done
|
||||||
|
|
||||||
install-i18n : all-i18n install-common
|
install-i18n : all-i18n install-common
|
||||||
cd $(SRC); ../bld/install-mo $(DESTDIR)$(LOCALEDIR) $(INSTALL)
|
cd $(BUILDDIR); $(top)/bld/install-mo $(DESTDIR)$(LOCALEDIR) $(INSTALL)
|
||||||
cd $(MAN); ../bld/install-man $(DESTDIR)$(MANDIR) $(INSTALL)
|
cd $(MAN); ../bld/install-man $(DESTDIR)$(MANDIR) $(INSTALL)
|
||||||
|
|
||||||
merge :
|
merge :
|
||||||
@cd $(SRC) && $(MAKE) -f ../Makefile dnsmasq.pot
|
@cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
|
||||||
@cd $(PO); for f in *.po; do \
|
for f in `cd $(PO); echo *.po`; do \
|
||||||
echo -n msgmerge $$f && $(MSGMERGE) --no-wrap -U $$f ../$(SRC)/dnsmasq.pot; \
|
echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
$(BUILDDIR):
|
||||||
|
mkdir -p $(BUILDDIR)
|
||||||
|
|
||||||
# rules below are targets in recusive makes with cwd=$(SRC)
|
|
||||||
|
# rules below are targets in recusive makes with cwd=$(BUILDDIR)
|
||||||
|
|
||||||
|
.configured: $(hdrs)
|
||||||
|
@rm -f *.o
|
||||||
|
@touch $@
|
||||||
|
|
||||||
|
$(objs:.o=.c) $(hdrs):
|
||||||
|
ln -s $(top)/$(SRC)/$@ .
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) $(COPTS) $(I18N) $(BUILD_CFLAGS) $(RPM_OPT_FLAGS) -c $<
|
$(CC) $(CFLAGS) $(COPTS) $(i18n) $(build_cflags) $(RPM_OPT_FLAGS) -c $<
|
||||||
|
|
||||||
dnsmasq : $(OBJS)
|
dnsmasq : .configured $(hdrs) $(objs)
|
||||||
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(BUILD_LIBS) $(LIBS)
|
$(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS)
|
||||||
|
|
||||||
dnsmasq.pot : $(OBJS:.o=.c) dnsmasq.h config.h
|
dnsmasq.pot : $(objs:.o=.c) $(hdrs)
|
||||||
$(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(OBJS:.o=.c)
|
$(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(objs:.o=.c)
|
||||||
|
|
||||||
%.mo : ../po/%.po dnsmasq.pot
|
%.mo : $(top)/$(PO)/%.po dnsmasq.pot
|
||||||
$(MSGMERGE) -o - ../po/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -
|
$(MSGMERGE) -o - $(top)/$(PO)/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -
|
||||||
|
|
||||||
|
|
||||||
.PHONY : all clean install install-common all-i18n install-i18n merge
|
.PHONY : all clean install install-common all-i18n install-i18n merge
|
||||||
+5
-1
@@ -6,7 +6,9 @@ include $(CLEAR_VARS)
|
|||||||
LOCAL_SRC_FILES := bpf.c cache.c dbus.c dhcp.c dnsmasq.c \
|
LOCAL_SRC_FILES := bpf.c cache.c dbus.c dhcp.c dnsmasq.c \
|
||||||
forward.c helper.c lease.c log.c \
|
forward.c helper.c lease.c log.c \
|
||||||
netlink.c network.c option.c rfc1035.c \
|
netlink.c network.c option.c rfc1035.c \
|
||||||
rfc2131.c tftp.c util.c conntrack.c
|
rfc2131.c tftp.c util.c conntrack.c \
|
||||||
|
dhcp6.c rfc3315.c dhcp-common.c outpacket.c \
|
||||||
|
radv.c slaac.c auth.c
|
||||||
|
|
||||||
LOCAL_MODULE := dnsmasq
|
LOCAL_MODULE := dnsmasq
|
||||||
|
|
||||||
@@ -15,4 +17,6 @@ LOCAL_C_INCLUDES := external/dnsmasq/src
|
|||||||
LOCAL_CFLAGS := -O2 -g -W -Wall -D__ANDROID__ -DNO_IPV6 -DNO_TFTP -DNO_SCRIPT
|
LOCAL_CFLAGS := -O2 -g -W -Wall -D__ANDROID__ -DNO_IPV6 -DNO_TFTP -DNO_SCRIPT
|
||||||
LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils
|
LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils
|
||||||
|
|
||||||
|
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
+10
-8
@@ -8,19 +8,21 @@
|
|||||||
# which has a set of references substituted into it by git.
|
# which has a set of references substituted into it by git.
|
||||||
# If we can find one which matches $v[0-9].* then we assume it's
|
# If we can find one which matches $v[0-9].* then we assume it's
|
||||||
# a version-number tag, else we just use the whole string.
|
# a version-number tag, else we just use the whole string.
|
||||||
|
# If there is more than one v[0-9].* tag, sort them and use the
|
||||||
|
# first. This favours, eg v2.63 over 2.63rc6.
|
||||||
|
|
||||||
# we're called with pwd == src
|
if which git >/dev/null 2>&1 && [ -d $1/.git ]; then
|
||||||
cd ..
|
cd $1; git describe
|
||||||
|
elif grep '\$Format:%d\$' $1/VERSION >/dev/null 2>&1; then
|
||||||
if [ -d .git ]; then
|
# unsubstituted VERSION, but no git available.
|
||||||
git describe
|
echo UNKNOWN
|
||||||
else
|
else
|
||||||
vers=`cat VERSION | sed 's/[(), ]/\n/ g' | grep -m 1 $v[0-9]`
|
vers=`cat $1/VERSION | sed 's/[(), ]/,/ g' | tr ',' '\n' | grep ^v[0-9]`
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo ${vers#v}
|
echo "${vers}" | sort | head -n 1 | sed 's/^v//'
|
||||||
else
|
else
|
||||||
cat VERSION
|
cat $1/VERSION
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,6 +4,6 @@ for f in *; do
|
|||||||
if [ -d $f ]; then
|
if [ -d $f ]; then
|
||||||
$2 -m 755 -d $1/$f/man8
|
$2 -m 755 -d $1/$f/man8
|
||||||
$2 -m 644 $f/dnsmasq.8 $1/$f/man8
|
$2 -m 644 $f/dnsmasq.8 $1/$f/man8
|
||||||
echo installing $1/$f/man8/dnsmasq.8
|
echo installing $f/man8/dnsmasq.8
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
for f in *.mo; do
|
for f in *.mo; do
|
||||||
$2 -m 755 -d $1/${f%.mo}/LC_MESSAGES
|
$2 -m 755 -d $1/${f%.mo}/LC_MESSAGES
|
||||||
$2 -m 644 $f $1/${f%.mo}/LC_MESSAGES/dnsmasq.mo
|
$2 -m 644 $f $1/${f%.mo}/LC_MESSAGES/dnsmasq.mo
|
||||||
echo installing $1/${f%.mo}/LC_MESSAGES/dnsmasq.mo
|
echo installing ${f%.mo}/LC_MESSAGES/dnsmasq.mo
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
+2
-2
@@ -3,8 +3,8 @@
|
|||||||
search=$1
|
search=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if grep "^\#[[:space:]]*define[[:space:]]*$search" config.h 2>&1 >/dev/null || \
|
if grep "^\#[[:space:]]*define[[:space:]]*$search" config.h >/dev/null 2>&1 || \
|
||||||
grep $search 2>&1 >/dev/null ; then
|
grep $search >/dev/null 2>&1; then
|
||||||
exec $*
|
exec $*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Executable
+43
@@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import dbus
|
||||||
|
|
||||||
|
bus = dbus.SystemBus()
|
||||||
|
p = bus.get_object("uk.org.thekelleys.dnsmasq", "/uk/org/thekelleys/dnsmasq")
|
||||||
|
l = dbus.Interface(p, dbus_interface="uk.org.thekelleys.dnsmasq")
|
||||||
|
|
||||||
|
# The new more flexible SetServersEx method
|
||||||
|
array = dbus.Array()
|
||||||
|
array.append(["1.2.3.5"])
|
||||||
|
array.append(["1.2.3.4#664", "foobar.com"])
|
||||||
|
array.append(["1003:1234:abcd::1%eth0", "eng.mycorp.com", "lab.mycorp.com"])
|
||||||
|
print l.SetServersEx(array)
|
||||||
|
|
||||||
|
# Must create a new object for dnsmasq as the introspection gives the wrong
|
||||||
|
# signature for SetServers (av) while the code only expects a bunch of arguments
|
||||||
|
# instead of an array of variants
|
||||||
|
p = bus.get_object("uk.org.thekelleys.dnsmasq", "/uk/org/thekelleys/dnsmasq", introspect=False)
|
||||||
|
l = dbus.Interface(p, dbus_interface="uk.org.thekelleys.dnsmasq")
|
||||||
|
|
||||||
|
# The previous method; all addresses in machine byte order
|
||||||
|
print l.SetServers(dbus.UInt32(16909060), # 1.2.3.5
|
||||||
|
dbus.UInt32(16909061), # 1.2.3.4
|
||||||
|
"foobar.com",
|
||||||
|
dbus.Byte(0x10), # 1003:1234:abcd::1
|
||||||
|
dbus.Byte(0x03),
|
||||||
|
dbus.Byte(0x12),
|
||||||
|
dbus.Byte(0x34),
|
||||||
|
dbus.Byte(0xab),
|
||||||
|
dbus.Byte(0xcd),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x00),
|
||||||
|
dbus.Byte(0x01),
|
||||||
|
"eng.mycorp.com",
|
||||||
|
"lab.mycorp.com")
|
||||||
|
|
||||||
@@ -34,11 +34,21 @@ if [ ${DNSMASQ_OLD_HOSTNAME} ] && [ ${action} = old ] ; then
|
|||||||
hostname=${DNSMASQ_OLD_HOSTNAME}
|
hostname=${DNSMASQ_OLD_HOSTNAME}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# IPv6 leases are not our concern. no NAT there!
|
||||||
|
if [ ${DNSMASQ_IAID} ] ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# action init is not relevant, and will only be seen when leasefile-ro is set.
|
# action init is not relevant, and will only be seen when leasefile-ro is set.
|
||||||
if [ ${action} = init ] ; then
|
if [ ${action} = init ] ; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# action tftp is not relevant.
|
||||||
|
if [ ${action} = tftp ] ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ${hostname} ]; then
|
if [ ${hostname} ]; then
|
||||||
ports=$(sed -n -e "/^${hostname}\ .*/ s/^.* //p" ${PORTSFILE})
|
ports=$(sed -n -e "/^${hostname}\ .*/ s/^.* //p" ${PORTSFILE})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
To: dnsmasq-discuss@lists.thekelleys.org.uk
|
||||||
|
From: Alex Elsayed <eternaleye+usenet@gmail.com>
|
||||||
|
Date: Tue, 15 May 2012 01:53:54 -0700
|
||||||
|
Subject: [Dnsmasq-discuss] [PATCH] Support dbus activation
|
||||||
|
|
||||||
|
Introduce dbus service file and turn dbus on in the systemd
|
||||||
|
unit.
|
||||||
|
|
||||||
|
Note to packagers:
|
||||||
|
To add support for dbus activation, you must install the dbus
|
||||||
|
service file (dbus/uk.org.thekelleys.dnsmasq.service) into
|
||||||
|
$DATADIR/dbus-1/system-services.
|
||||||
|
|
||||||
|
---
|
||||||
|
contrib/systemd/dnsmasq.service | 2 +-
|
||||||
|
dbus/uk.org.thekelleys.dnsmasq.service | 7 +++++++
|
||||||
|
2 files changed, 8 insertions(+), 1 deletion(-)
|
||||||
|
create mode 100644 dbus/uk.org.thekelleys.dnsmasq.service
|
||||||
|
|
||||||
|
diff --git a/contrib/systemd/dnsmasq.service
|
||||||
|
b/contrib/systemd/dnsmasq.service
|
||||||
|
index a27fe6d..4a784d3 100644
|
||||||
|
--- a/contrib/systemd/dnsmasq.service
|
||||||
|
+++ b/contrib/systemd/dnsmasq.service
|
||||||
|
@@ -5,7 +5,7 @@ Description=A lightweight DHCP and caching DNS server
|
||||||
|
Type=dbus
|
||||||
|
BusName=uk.org.thekelleys.dnsmasq
|
||||||
|
ExecStartPre=/usr/sbin/dnsmasq --test
|
||||||
|
-ExecStart=/usr/sbin/dnsmasq -k
|
||||||
|
+ExecStart=/usr/sbin/dnsmasq -k -1
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
diff --git a/dbus/uk.org.thekelleys.dnsmasq.service
|
||||||
|
b/dbus/uk.org.thekelleys.dnsmasq.service
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..f5fe98d
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/dbus/uk.org.thekelleys.dnsmasq.service
|
||||||
|
@@ -0,0 +1,7 @@
|
||||||
|
+[D-BUS Service]
|
||||||
|
+Name=uk.org.thekelleys.dnsmasq
|
||||||
|
+Exec=/usr/sbin/dnsmasq -k -1
|
||||||
|
+User=root
|
||||||
|
+SystemdService=dnsmasq.service
|
||||||
|
+
|
||||||
|
+
|
||||||
|
--
|
||||||
|
1.7.10.2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_______________________________________________
|
||||||
|
Dnsmasq-discuss mailing list
|
||||||
|
Dnsmasq-discuss@lists.thekelleys.org.uk
|
||||||
|
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
|
||||||
|
|
||||||
+61
-1
@@ -19,7 +19,8 @@ and avoids startup races with the provider of nameserver information.
|
|||||||
|
|
||||||
|
|
||||||
Dnsmasq provides one service on the DBus: uk.org.thekelleys.dnsmasq
|
Dnsmasq provides one service on the DBus: uk.org.thekelleys.dnsmasq
|
||||||
and a single object: /uk/org/thekelleys/dnsmasq
|
and a single object: /uk/org/thekelleys/dnsmasq
|
||||||
|
The name of the service may be changed by giving an argument to --enable-dbus.
|
||||||
|
|
||||||
1. METHODS
|
1. METHODS
|
||||||
----------
|
----------
|
||||||
@@ -94,6 +95,65 @@ Each call to SetServers completely replaces the set of servers
|
|||||||
specified by via the DBus, but it leaves any servers specified via the
|
specified by via the DBus, but it leaves any servers specified via the
|
||||||
command line or /etc/dnsmasq.conf or /etc/resolv.conf alone.
|
command line or /etc/dnsmasq.conf or /etc/resolv.conf alone.
|
||||||
|
|
||||||
|
SetServersEx
|
||||||
|
------------
|
||||||
|
|
||||||
|
This function is more flexible and the SetServers function, in that it can
|
||||||
|
handle address scoping, port numbers, and is easier for clients to use.
|
||||||
|
|
||||||
|
Returns nothing. Takes a set of arguments representing the new
|
||||||
|
upstream DNS servers to be used by dnsmasq. All addresses (both IPv4 and IPv6)
|
||||||
|
are represented as STRINGS. Each server address may be followed by one or more
|
||||||
|
STRINGS, which are the domains for which the preceding server should be used.
|
||||||
|
|
||||||
|
This function takes an array of STRING arrays, where each inner array represents
|
||||||
|
a set of DNS servers and domains for which those servers may be used. Each
|
||||||
|
string represents a list of upstream DNS servers first, and domains second.
|
||||||
|
Mixing of domains and servers within a the string array is not allowed.
|
||||||
|
|
||||||
|
Examples.
|
||||||
|
|
||||||
|
[
|
||||||
|
["1.2.3.4", "foobar.com"],
|
||||||
|
["1003:1234:abcd::1%eth0", "eng.mycorp.com", "lab.mycorp.com"]
|
||||||
|
]
|
||||||
|
|
||||||
|
is equivalent to
|
||||||
|
|
||||||
|
--server=/foobar.com/1.2.3.4 \
|
||||||
|
--server=/eng.mycorp.com/lab.mycorp.com/1003:1234:abcd::1%eth0
|
||||||
|
|
||||||
|
An IPv4 address of 0.0.0.0 is interpreted as "no address, local only",
|
||||||
|
so
|
||||||
|
|
||||||
|
[ ["0.0.0.0", "local.domain"] ]
|
||||||
|
|
||||||
|
is equivalent to
|
||||||
|
|
||||||
|
--local=/local.domain/
|
||||||
|
|
||||||
|
|
||||||
|
Each call to SetServersEx completely replaces the set of servers
|
||||||
|
specified by via the DBus, but it leaves any servers specified via the
|
||||||
|
command line or /etc/dnsmasq.conf or /etc/resolv.conf alone.
|
||||||
|
|
||||||
|
|
||||||
|
SetDomainServers
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Yes another variation for setting DNS servers, with the capability of
|
||||||
|
SetServersEx, but without using arrays of arrays, which are not
|
||||||
|
sendable with dbus-send. The arguments are an array of strings which
|
||||||
|
are identical to the equivalent arguments --server, so the example
|
||||||
|
for SetServersEx is represented as
|
||||||
|
|
||||||
|
[
|
||||||
|
"/foobar.com/1.2.3.4"
|
||||||
|
"/eng.mycorp.com/lab.mycorp.com/1003:1234:abcd::1%eth0"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
2. SIGNALS
|
2. SIGNALS
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|||||||
Vendored
+83
@@ -1,3 +1,86 @@
|
|||||||
|
dnsmasq (2.66-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* New upstream.
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Fri, 14 Dec 2012 11:58:41 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.65-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* New upstream.
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Fri, 14 Dec 2012 11:34:12 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.64-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* New upstream.
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Fri, 21 Sep 2012 17:17:22 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.63-4) unstable; urgency=low
|
||||||
|
|
||||||
|
* Make pid-file creation immune to symlink attacks. (closes: #686484)
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Fri, 21 Sep 2012 17:16:34 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.63-3) unstable; urgency=low
|
||||||
|
|
||||||
|
* Move adduser dependency to dnsmasq-base. (closes: #686694)
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Tue, 4 Sep 2012 21:44:15 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.63-2) unstable; urgency=low
|
||||||
|
|
||||||
|
* Fix version script to report correct version.
|
||||||
|
* Unbotch move of dbus config file by using correct versions in
|
||||||
|
Replaces: and Breaks: lines. (closes: #685204)
|
||||||
|
* Create dnsmasq user in dnsmasq-base so that Dbus doesn't complain if
|
||||||
|
only dnsmasq-base is installed. (closes: #685987)
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Tue, 28 Aug 2012 16:18:35 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.63-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* New upstream.
|
||||||
|
* Move /etc/dbus-1/system.d/dnsmasq.conf from dnsmasq to dnsmasq-base.
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Mon, 11 Jun 2012 21:55:35 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.62-3) unstable; urgency=low
|
||||||
|
|
||||||
|
* Do resolvconf and /etc/default startup logic when
|
||||||
|
starting with systemd. (closes: #675854)
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Mon, 11 Jun 2012 21:50:11 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.62-2) unstable; urgency=low
|
||||||
|
|
||||||
|
* Pass LDFLAGS to make to get hardening in linker.
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Thu, 7 Jun 2012 09:53:43 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.62-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* New upstream.
|
||||||
|
* Use dpkg-buildflags. (Enables hardening).
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Sat, 12 May 2012 15:25:23 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.61-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* New upstream.
|
||||||
|
* Provide "dump-stats" initscript method. (closes: #654656)
|
||||||
|
* Add (empty) build-indep and build-arch rules targets.
|
||||||
|
* Bump standards-version to 3.9.3
|
||||||
|
* Add port option to example dnsmasq.conf (closes: #668386)
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Tue, 6 Mar 2012 19:45:43 +0000
|
||||||
|
|
||||||
|
dnsmasq (2.60-2) unstable; urgency=high
|
||||||
|
|
||||||
|
* Fix DHCPv4 segfault. (closes: #665008)
|
||||||
|
|
||||||
|
-- Simon Kelley <simon@thekelleys.org.uk> Fri, 23 Mar 2012 09:37:23 +0000
|
||||||
|
|
||||||
dnsmasq (2.60-1) unstable; urgency=low
|
dnsmasq (2.60-1) unstable; urgency=low
|
||||||
|
|
||||||
* New upstream.
|
* New upstream.
|
||||||
|
|||||||
Vendored
-1
@@ -2,5 +2,4 @@
|
|||||||
/etc/default/dnsmasq
|
/etc/default/dnsmasq
|
||||||
/etc/dnsmasq.conf
|
/etc/dnsmasq.conf
|
||||||
/etc/resolvconf/update.d/dnsmasq
|
/etc/resolvconf/update.d/dnsmasq
|
||||||
/etc/dbus-1/system.d/dnsmasq.conf
|
|
||||||
/etc/insserv.conf.d/dnsmasq
|
/etc/insserv.conf.d/dnsmasq
|
||||||
Vendored
+5
-4
@@ -3,11 +3,11 @@ Section: net
|
|||||||
Priority: optional
|
Priority: optional
|
||||||
Build-depends: gettext, libnetfilter-conntrack-dev [linux-any], libidn11-dev, libdbus-1-dev (>=0.61)
|
Build-depends: gettext, libnetfilter-conntrack-dev [linux-any], libidn11-dev, libdbus-1-dev (>=0.61)
|
||||||
Maintainer: Simon Kelley <simon@thekelleys.org.uk>
|
Maintainer: Simon Kelley <simon@thekelleys.org.uk>
|
||||||
Standards-Version: 3.9.2
|
Standards-Version: 3.9.3
|
||||||
|
|
||||||
Package: dnsmasq
|
Package: dnsmasq
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: netbase, adduser, dnsmasq-base(>= ${source:Version})
|
Depends: netbase, dnsmasq-base(>= ${source:Version})
|
||||||
Suggests: resolvconf
|
Suggests: resolvconf
|
||||||
Conflicts: resolvconf (<<1.15)
|
Conflicts: resolvconf (<<1.15)
|
||||||
Description: Small caching DNS proxy and DHCP/TFTP server
|
Description: Small caching DNS proxy and DHCP/TFTP server
|
||||||
@@ -22,8 +22,9 @@ Description: Small caching DNS proxy and DHCP/TFTP server
|
|||||||
|
|
||||||
Package: dnsmasq-base
|
Package: dnsmasq-base
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: ${shlibs:Depends}
|
Depends: adduser, ${shlibs:Depends}
|
||||||
Conflicts: dnsmasq (<<2.41)
|
Breaks: dnsmasq (<< 2.63-1~)
|
||||||
|
Replaces: dnsmasq (<< 2.63-1~)
|
||||||
Description: Small caching DNS proxy and DHCP/TFTP server
|
Description: Small caching DNS proxy and DHCP/TFTP server
|
||||||
This package contains the dnsmasq executable and documentation, but
|
This package contains the dnsmasq executable and documentation, but
|
||||||
not the infrastructure required to run it as a system daemon. For
|
not the infrastructure required to run it as a system daemon. For
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
/etc/dbus-1/system.d/dnsmasq.conf
|
||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Create the dnsmasq user in dnsmasq-base, so that Dbus doesn't complain.
|
||||||
|
|
||||||
|
# create a user to run as (code stolen from dovecot-common)
|
||||||
|
if [ "$1" = "configure" ]; then
|
||||||
|
if [ -z "`id -u dnsmasq 2> /dev/null`" ]; then
|
||||||
|
adduser --system --home /var/lib/misc --gecos "dnsmasq" \
|
||||||
|
--no-create-home --disabled-password \
|
||||||
|
--quiet dnsmasq || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make the directory where we keep the pid file - this
|
||||||
|
# has to be owned by "dnsmasq" so that the file can be unlinked.
|
||||||
|
# This is only actually used by the dnsmasq binary package, not
|
||||||
|
# dnsmasq-base, but it's much easier to create it here so that
|
||||||
|
# we don't have synchronisation issues with the creation of the
|
||||||
|
# dnsmasq user.
|
||||||
|
if [ ! -d /var/run/dnsmasq ]; then
|
||||||
|
mkdir /var/run/dnsmasq
|
||||||
|
chown dnsmasq:nogroup /var/run/dnsmasq
|
||||||
|
fi
|
||||||
|
fi
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ purge = "$1" ]; then
|
||||||
|
if [ -x "$(command -v deluser)" ]; then
|
||||||
|
deluser --quiet --system dnsmasq > /dev/null || true
|
||||||
|
else
|
||||||
|
echo >&2 "not removing dnsmasq system account because deluser command was not found"
|
||||||
|
fi
|
||||||
|
rm -rf /var/run/dnsmasq
|
||||||
|
fi
|
||||||
Vendored
+25
-1
@@ -256,8 +256,32 @@ case "$1" in
|
|||||||
*) log_success_msg "(unknown)" ; exit 4 ;;
|
*) log_success_msg "(unknown)" ; exit 4 ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
dump-stats)
|
||||||
|
kill -s USR1 `cat /var/run/dnsmasq/$NAME.pid`
|
||||||
|
;;
|
||||||
|
systemd-start-resolvconf)
|
||||||
|
start_resolvconf
|
||||||
|
;;
|
||||||
|
systemd-stop-resolvconf)
|
||||||
|
stop_resolvconf
|
||||||
|
;;
|
||||||
|
systemd-exec)
|
||||||
|
# --pid-file without argument disables writing a PIDfile, we don't need one with sytemd.
|
||||||
|
# Enable DBus by default because we use DBus activation with systemd.
|
||||||
|
exec $DAEMON --keep-in-foreground --pid-file --enable-dbus \
|
||||||
|
${MAILHOSTNAME:+ -m $MAILHOSTNAME} \
|
||||||
|
${MAILTARGET:+ -t $MAILTARGET} \
|
||||||
|
${DNSMASQ_USER:+ -u $DNSMASQ_USER} \
|
||||||
|
${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \
|
||||||
|
${DHCP_LEASE:+ -l $DHCP_LEASE} \
|
||||||
|
${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \
|
||||||
|
${RESOLV_CONF:+ -r $RESOLV_CONF} \
|
||||||
|
${CACHESIZE:+ -c $CACHESIZE} \
|
||||||
|
${CONFIG_DIR:+ -7 $CONFIG_DIR} \
|
||||||
|
${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2
|
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|dump-stats|status}" >&2
|
||||||
exit 3
|
exit 3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Vendored
-27
@@ -1,27 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# create a user to run as (code stolen from dovecot-common)
|
|
||||||
if [ "$1" = "configure" ]; then
|
|
||||||
if [ -z "`id -u dnsmasq 2> /dev/null`" ]; then
|
|
||||||
adduser --system --home /var/lib/misc --gecos "dnsmasq" \
|
|
||||||
--no-create-home --disabled-password \
|
|
||||||
--quiet dnsmasq || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Make the directory where we keep the pid file - this
|
|
||||||
# has to be owned by "dnsmasq" do that the file can be unlinked.
|
|
||||||
if [ ! -d /var/run/dnsmasq ]; then
|
|
||||||
mkdir /var/run/dnsmasq
|
|
||||||
chown dnsmasq:nogroup /var/run/dnsmasq
|
|
||||||
fi
|
|
||||||
|
|
||||||
# handle new location of pidfile during an upgrade
|
|
||||||
if [ -e /var/run/dnsmasq.pid ]; then
|
|
||||||
mv /var/run/dnsmasq.pid /var/run/dnsmasq
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -x /etc/init.d/dnsmasq ]; then
|
if [ -x /etc/init.d/dnsmasq ]; then
|
||||||
update-rc.d dnsmasq defaults 15 85 >/dev/null
|
update-rc.d dnsmasq defaults 15 85 >/dev/null
|
||||||
|
|
||||||
@@ -40,10 +19,4 @@ if [ -x /etc/init.d/dnsmasq ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# dpkg can botch the change of /usr/share/doc/dnsmasq from
|
|
||||||
# directory to symlink. Fix up here.
|
|
||||||
if [ ! -h /usr/share/doc/dnsmasq ] && { rmdir /usr/share/doc/dnsmasq; }; then
|
|
||||||
cd /usr/share/doc/
|
|
||||||
ln -s /usr/share/doc/dnsmasq-base dnsmasq
|
|
||||||
fi
|
|
||||||
|
|
||||||
Vendored
-6
@@ -3,10 +3,4 @@ set -e
|
|||||||
|
|
||||||
if [ purge = "$1" ]; then
|
if [ purge = "$1" ]; then
|
||||||
update-rc.d dnsmasq remove >/dev/null
|
update-rc.d dnsmasq remove >/dev/null
|
||||||
if [ -x "$(command -v deluser)" ]; then
|
|
||||||
deluser --quiet --system dnsmasq > /dev/null || true
|
|
||||||
else
|
|
||||||
echo >&2 "not removing dnsmasq system account because deluser command was not found"
|
|
||||||
fi
|
|
||||||
rm -rf /var/run/dnsmasq
|
|
||||||
fi
|
fi
|
||||||
Vendored
+8
-2
@@ -52,7 +52,10 @@ Notes on configuring dnsmasq as packaged for Debian.
|
|||||||
nodocs : omit documentation.
|
nodocs : omit documentation.
|
||||||
notftp : omit TFTP support.
|
notftp : omit TFTP support.
|
||||||
nodhcp : omit DHCP support.
|
nodhcp : omit DHCP support.
|
||||||
|
nodhcp6 : omit DHCPv6 support.
|
||||||
noscript : omit lease-change script support.
|
noscript : omit lease-change script support.
|
||||||
|
use_lua : provide support for lease-change scripts written
|
||||||
|
in Lua.
|
||||||
noipv6 : omit IPv6 support.
|
noipv6 : omit IPv6 support.
|
||||||
nodbus : omit DBus support.
|
nodbus : omit DBus support.
|
||||||
noconntrack : omit connection tracking support.
|
noconntrack : omit connection tracking support.
|
||||||
@@ -60,11 +63,14 @@ Notes on configuring dnsmasq as packaged for Debian.
|
|||||||
noi18n : omit translations and internationalisation support.
|
noi18n : omit translations and internationalisation support.
|
||||||
noidn : omit international domain name support, must be
|
noidn : omit international domain name support, must be
|
||||||
combined with noi18n to be effective.
|
combined with noi18n to be effective.
|
||||||
|
|
||||||
|
|
||||||
(9) Dnsmasq comes as two packages - dnsmasq-base and
|
(9) Dnsmasq comes as three packages - dnsmasq-utils, dnsmasq-base and
|
||||||
dnsmasq. dnsmasq-base provides the dnsmasq executable and
|
dnsmasq. Dnsmasq-base provides the dnsmasq executable and
|
||||||
documentation (including this file). Dnsmasq, which depends on
|
documentation (including this file). Dnsmasq, which depends on
|
||||||
dnsmasq-base, provides the init script and configuration
|
dnsmasq-base, provides the init script and configuration
|
||||||
infrastructure. This file assumes that both are installed. It is
|
infrastructure. This file assumes that both are installed. It is
|
||||||
possible to install only dnsmasq-base and use dnsmasq as a
|
possible to install only dnsmasq-base and use dnsmasq as a
|
||||||
non-"system" daemon. Libvirt, for instance, does this.
|
non-"system" daemon. Libvirt, for instance, does this.
|
||||||
|
Dnsmasq-utils provides the utilities dhcp_release and
|
||||||
|
dhcp_lease_time.
|
||||||
Vendored
+33
-19
@@ -11,55 +11,63 @@
|
|||||||
|
|
||||||
package=dnsmasq-base
|
package=dnsmasq-base
|
||||||
|
|
||||||
# policy manual, section 10.1
|
CFLAGS = $(shell export DEB_BUILD_OPTIONS=$(DEB_BUILD_OPTIONS); dpkg-buildflags --get CFLAGS)
|
||||||
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
|
CFLAGS += $(shell dpkg-buildflags --get CPPFLAGS)
|
||||||
CFLAGS = -g -O0 -Wall -W
|
CFLAGS += -Wall -W
|
||||||
else
|
|
||||||
CFLAGS = -g -O2 -Wall -W
|
LDFLAGS = $(shell dpkg-buildflags --get LDFLAGS)
|
||||||
endif
|
|
||||||
|
|
||||||
COPTS =
|
COPTS =
|
||||||
|
|
||||||
TARGET = install-i18n
|
TARGET = install-i18n
|
||||||
|
|
||||||
DEB_BUILD_ARCH_OS := $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
|
DEB_BUILD_ARCH_OS := $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
|
||||||
|
|
||||||
ifeq (,$(findstring nodbus,$(DEB_BUILD_OPTIONS)))
|
ifeq (,$(filter nodbus,$(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DHAVE_DBUS
|
COPTS += -DHAVE_DBUS
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq (,$(findstring noconntrack,$(DEB_BUILD_OPTIONS)))
|
ifeq (,$(filter noconntrack,$(DEB_BUILD_OPTIONS)))
|
||||||
ifeq ($(DEB_BUILD_ARCH_OS),linux)
|
ifeq ($(DEB_BUILD_ARCH_OS),linux)
|
||||||
COPTS += -DHAVE_CONNTRACK
|
COPTS += -DHAVE_CONNTRACK
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(findstring noipv6,$(DEB_BUILD_OPTIONS)))
|
ifneq (,$(filter nodhcp6,$(DEB_BUILD_OPTIONS)))
|
||||||
|
COPTS += -DNO_DHCP6
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter noipv6,$(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DNO_IPV6
|
COPTS += -DNO_IPV6
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(findstring notftp,$(DEB_BUILD_OPTIONS)))
|
ifneq (,$(filter notftp,$(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DNO_TFTP
|
COPTS += -DNO_TFTP
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(findstring nodhcp,$(DEB_BUILD_OPTIONS)))
|
ifneq (,$(filter nodhcp,$(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DNO_DHCP
|
COPTS += -DNO_DHCP
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(findstring noscript,$(DEB_BUILD_OPTIONS)))
|
ifneq (,$(filter noscript,$(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DNO_SCRIPT
|
COPTS += -DNO_SCRIPT
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(findstring nortc,$(DEB_BUILD_OPTIONS)))
|
ifneq (,$(filter nortc,$(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DHAVE_BROKEN_RTC
|
COPTS += -DHAVE_BROKEN_RTC
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(findstring noi18n,$(DEB_BUILD_OPTIONS)))
|
ifneq (,$(filter noi18n,$(DEB_BUILD_OPTIONS)))
|
||||||
TARGET = install
|
TARGET = install
|
||||||
ifeq (,$(findstring noidn, $(DEB_BUILD_OPTIONS)))
|
ifeq (,$(filter noidn, $(DEB_BUILD_OPTIONS)))
|
||||||
COPTS += -DHAVE_IDN
|
COPTS += -DHAVE_IDN
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter uselua,$(DEB_BUILD_OPTIONS)))
|
||||||
|
COPTS += -DHAVE_LUASCRIPT
|
||||||
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(checkdir)
|
$(checkdir)
|
||||||
rm -rf debian/daemon debian/base debian/utils debian/*~ debian/files debian/substvars debian/utils-substvars
|
rm -rf debian/daemon debian/base debian/utils debian/*~ debian/files debian/substvars debian/utils-substvars
|
||||||
@@ -77,7 +85,6 @@ binary-indep: checkroot
|
|||||||
-d debian/daemon/etc/resolvconf/update.d \
|
-d debian/daemon/etc/resolvconf/update.d \
|
||||||
-d debian/daemon/usr/lib/resolvconf/dpkg-event.d \
|
-d debian/daemon/usr/lib/resolvconf/dpkg-event.d \
|
||||||
-d debian/daemon/etc/default \
|
-d debian/daemon/etc/default \
|
||||||
-d debian/daemon/etc/dbus-1/system.d \
|
|
||||||
-d debian/daemon/lib/systemd/system \
|
-d debian/daemon/lib/systemd/system \
|
||||||
-d debian/daemon/etc/insserv.conf.d
|
-d debian/daemon/etc/insserv.conf.d
|
||||||
install -m 644 debian/conffiles debian/daemon/DEBIAN
|
install -m 644 debian/conffiles debian/daemon/DEBIAN
|
||||||
@@ -88,7 +95,6 @@ binary-indep: checkroot
|
|||||||
install -m 644 debian/default debian/daemon/etc/default/dnsmasq
|
install -m 644 debian/default debian/daemon/etc/default/dnsmasq
|
||||||
install -m 644 dnsmasq.conf.example debian/daemon/etc/dnsmasq.conf
|
install -m 644 dnsmasq.conf.example debian/daemon/etc/dnsmasq.conf
|
||||||
install -m 644 debian/readme.dnsmasq.d debian/daemon/etc/dnsmasq.d/README
|
install -m 644 debian/readme.dnsmasq.d debian/daemon/etc/dnsmasq.d/README
|
||||||
install -m 644 debian/dbus.conf debian/daemon/etc/dbus-1/system.d/dnsmasq.conf
|
|
||||||
install -m 644 debian/systemd.service debian/daemon/lib/systemd/system/dnsmasq.service
|
install -m 644 debian/systemd.service debian/daemon/lib/systemd/system/dnsmasq.service
|
||||||
install -m 644 debian/insserv debian/daemon/etc/insserv.conf.d/dnsmasq
|
install -m 644 debian/insserv debian/daemon/etc/insserv.conf.d/dnsmasq
|
||||||
ln -s $(package) debian/daemon/usr/share/doc/dnsmasq
|
ln -s $(package) debian/daemon/usr/share/doc/dnsmasq
|
||||||
@@ -103,11 +109,12 @@ binary-arch: checkroot
|
|||||||
rm -rf debian/base
|
rm -rf debian/base
|
||||||
install -m 755 \
|
install -m 755 \
|
||||||
-d debian/base/DEBIAN \
|
-d debian/base/DEBIAN \
|
||||||
|
-d debian/base/etc/dbus-1/system.d \
|
||||||
-d debian/base/usr/share/doc/$(package) \
|
-d debian/base/usr/share/doc/$(package) \
|
||||||
-d debian/base/usr/share/doc/$(package)/examples \
|
-d debian/base/usr/share/doc/$(package)/examples \
|
||||||
-d debian/base/var/run \
|
-d debian/base/var/run \
|
||||||
-d debian/base/var/lib/misc
|
-d debian/base/var/lib/misc
|
||||||
make $(TARGET) PREFIX=/usr DESTDIR=`pwd`/debian/base CFLAGS="$(CFLAGS)" COPTS="$(COPTS)" CC=gcc
|
make $(TARGET) PREFIX=/usr DESTDIR=`pwd`/debian/base CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" COPTS="$(COPTS)" CC=gcc
|
||||||
ifeq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
|
ifeq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
|
||||||
install -m 644 doc.html debian/base/usr/share/doc/$(package)/.
|
install -m 644 doc.html debian/base/usr/share/doc/$(package)/.
|
||||||
install -m 644 setup.html debian/base/usr/share/doc/$(package)/.
|
install -m 644 setup.html debian/base/usr/share/doc/$(package)/.
|
||||||
@@ -121,10 +128,14 @@ ifeq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
|
|||||||
install -m 644 dbus/DBus-interface debian/base/usr/share/doc/$(package)/.
|
install -m 644 dbus/DBus-interface debian/base/usr/share/doc/$(package)/.
|
||||||
gzip -9 debian/base/usr/share/doc/$(package)/DBus-interface
|
gzip -9 debian/base/usr/share/doc/$(package)/DBus-interface
|
||||||
endif
|
endif
|
||||||
|
install -m 644 debian/dnsmasq-base.conffiles debian/base/DEBIAN/conffiles
|
||||||
|
install -m 755 debian/dnsmasq-base.postinst debian/base/DEBIAN/postinst
|
||||||
|
install -m 755 debian/dnsmasq-base.postrm debian/base/DEBIAN/postrm
|
||||||
install -m 644 debian/changelog debian/base/usr/share/doc/$(package)/changelog.Debian
|
install -m 644 debian/changelog debian/base/usr/share/doc/$(package)/changelog.Debian
|
||||||
gzip -9 debian/base/usr/share/doc/$(package)/changelog.Debian
|
gzip -9 debian/base/usr/share/doc/$(package)/changelog.Debian
|
||||||
install -m 644 debian/readme debian/base/usr/share/doc/$(package)/README.Debian
|
install -m 644 debian/readme debian/base/usr/share/doc/$(package)/README.Debian
|
||||||
install -m 644 debian/copyright debian/base/usr/share/doc/$(package)/copyright
|
install -m 644 debian/copyright debian/base/usr/share/doc/$(package)/copyright
|
||||||
|
install -m 644 debian/dbus.conf debian/base/etc/dbus-1/system.d/dnsmasq.conf
|
||||||
gzip -9 debian/base/usr/share/man/man8/dnsmasq.8
|
gzip -9 debian/base/usr/share/man/man8/dnsmasq.8
|
||||||
for f in debian/base/usr/share/man/*; do \
|
for f in debian/base/usr/share/man/*; do \
|
||||||
if [ -f $$f/man8/dnsmasq.8 ]; then \
|
if [ -f $$f/man8/dnsmasq.8 ]; then \
|
||||||
@@ -147,7 +158,7 @@ ifeq ($(DEB_BUILD_ARCH_OS),linux)
|
|||||||
-d debian/utils/usr/share/man/man1 \
|
-d debian/utils/usr/share/man/man1 \
|
||||||
-d debian/utils/usr/bin \
|
-d debian/utils/usr/bin \
|
||||||
-d debian/utils/usr/share/doc/dnsmasq-utils
|
-d debian/utils/usr/share/doc/dnsmasq-utils
|
||||||
make -C contrib/wrt PREFIX=/usr DESTDIR=`pwd`/debian/utils CFLAGS="$(CFLAGS)" COPTS="$(COPTS)" CC=gcc
|
make -C contrib/wrt PREFIX=/usr DESTDIR=`pwd`/debian/utils CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" COPTS="$(COPTS)" CC=gcc
|
||||||
install -m 755 contrib/wrt/dhcp_release debian/utils/usr/bin/dhcp_release
|
install -m 755 contrib/wrt/dhcp_release debian/utils/usr/bin/dhcp_release
|
||||||
install -m 644 contrib/wrt/dhcp_release.1 debian/utils/usr/share/man/man1/dhcp_release.1
|
install -m 644 contrib/wrt/dhcp_release.1 debian/utils/usr/share/man/man1/dhcp_release.1
|
||||||
gzip -9 debian/utils/usr/share/man/man1/dhcp_release.1
|
gzip -9 debian/utils/usr/share/man/man1/dhcp_release.1
|
||||||
@@ -176,7 +187,10 @@ endef
|
|||||||
# Below here is fairly generic really
|
# Below here is fairly generic really
|
||||||
|
|
||||||
binary: binary-arch binary-indep
|
binary: binary-arch binary-indep
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
build-arch:
|
||||||
|
build-indep:
|
||||||
|
|
||||||
checkroot:
|
checkroot:
|
||||||
test root = "`whoami`"
|
test root = "`whoami`"
|
||||||
|
|||||||
Vendored
+16
-14
@@ -8,22 +8,24 @@ BusName=uk.org.thekelleys.dnsmasq
|
|||||||
# Test the config file and refuse starting if it is not valid.
|
# Test the config file and refuse starting if it is not valid.
|
||||||
ExecStartPre=/usr/sbin/dnsmasq --test
|
ExecStartPre=/usr/sbin/dnsmasq --test
|
||||||
|
|
||||||
# Enable DBus by default because we use DBus activation.
|
# We run dnsmasq via the /etc/init.d/dnsmasq script which acts as a
|
||||||
|
# wrapper picking up extra configuration files and then execs dnsmasq
|
||||||
|
# itself, when called with the "systemd-exec" function.
|
||||||
#
|
#
|
||||||
# Drop privileges and become the 'dnsmasq' user. It is recommended by dnsmasq
|
# It also adds the command-line flags
|
||||||
# upstream to run dnsmasq as an isolated user that does not run any other
|
# --keep-in-foreground --pid-file --enable-dbus
|
||||||
# processes, owns no files and has no shell. The default 'nobody' user has a
|
# to disable writing a pid-file (not needed with systemd) and
|
||||||
# shell and might be used for other processes.
|
# enable DBus by default because we use DBus activation.
|
||||||
#
|
#
|
||||||
# Debian-specific: add /etc/dnsmasq.d to config search path (with the exception
|
ExecStart=/etc/init.d/dnsmasq systemd-exec
|
||||||
# of .dpkg-*). Packages such as libvirt leave config files there.
|
|
||||||
#
|
# The systemd-*-resolvconf functions configure (and deconfigure)
|
||||||
# --pid-file without argument disables writing a PIDfile, we don't need one.
|
# resolvconf to work with the dnsmasq DNS server. They're called liek
|
||||||
ExecStart=/usr/sbin/dnsmasq -k \
|
# this to get correct error handling (ie don't start-resolvconf if the
|
||||||
--enable-dbus \
|
# dnsmasq daemon fails to start.
|
||||||
--user=dnsmasq \
|
ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf
|
||||||
-7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new \
|
ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf
|
||||||
--pid-file
|
|
||||||
|
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
|
||||||
|
|||||||
+62
-3
@@ -4,6 +4,11 @@
|
|||||||
# as the long options legal on the command line. See
|
# as the long options legal on the command line. See
|
||||||
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
|
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
|
||||||
|
|
||||||
|
# Listen on this specific port instead of the standard DNS port
|
||||||
|
# (53). Setting this to zero completely disables DNS function,
|
||||||
|
# leaving only DHCP and/or TFTP.
|
||||||
|
#port=5353
|
||||||
|
|
||||||
# The following two options make you a better netizen, since they
|
# The following two options make you a better netizen, since they
|
||||||
# tell dnsmasq to filter out queries which the public DNS cannot
|
# tell dnsmasq to filter out queries which the public DNS cannot
|
||||||
# answer, and which load the servers (especially the root servers)
|
# answer, and which load the servers (especially the root servers)
|
||||||
@@ -157,6 +162,44 @@
|
|||||||
# an explicit netmask instead.
|
# an explicit netmask instead.
|
||||||
#dhcp-range=192.168.0.0,static
|
#dhcp-range=192.168.0.0,static
|
||||||
|
|
||||||
|
# Enable DHCPv6. Note that the prefix-length does not need to be specified
|
||||||
|
# and defaults to 64 if missing/
|
||||||
|
#dhcp-range=1234::2, 1234::500, 64, 12h
|
||||||
|
|
||||||
|
# Do Router Advertisements, BUT NOT DHCP for this subnet.
|
||||||
|
#dhcp-range=1234::, ra-only
|
||||||
|
|
||||||
|
# Do Router Advertisements, BUT NOT DHCP for this subnet, also try and
|
||||||
|
# add names to the DNS for the IPv6 address of SLAAC-configured dual-stack
|
||||||
|
# hosts. Use the DHCPv4 lease to derive the name, network segment and
|
||||||
|
# MAC address and assume that the host will also have an
|
||||||
|
# IPv6 address calculated using the SLAAC alogrithm.
|
||||||
|
#dhcp-range=1234::, ra-names
|
||||||
|
|
||||||
|
# Do Router Advertisements, BUT NOT DHCP for this subnet.
|
||||||
|
# Set the lifetime to 46 hours. (Note: minimum lifetime is 2 hours.)
|
||||||
|
#dhcp-range=1234::, ra-only, 48h
|
||||||
|
|
||||||
|
# Do DHCP and Router Advertisements for this subnet. Set the A bit in the RA
|
||||||
|
# so that clients can use SLAAC addresses as well as DHCP ones.
|
||||||
|
#dhcp-range=1234::2, 1234::500, slaac
|
||||||
|
|
||||||
|
# Do Router Advertisements and stateless DHCP for this subnet. Clients will
|
||||||
|
# not get addresses from DHCP, but they will get other configuration information.
|
||||||
|
# They will use SLAAC for addresses.
|
||||||
|
#dhcp-range=1234::, ra-stateless
|
||||||
|
|
||||||
|
# Do stateless DHCP, SLAAC, and generate DNS names for SLAAC addresses
|
||||||
|
# from DHCPv4 leases.
|
||||||
|
#dhcp-range=1234::, ra-stateless, ra-names
|
||||||
|
|
||||||
|
# Do router advertisements for all subnets where we're doing DHCPv6
|
||||||
|
# Unless overriden by ra-stateless, ra-names, et al, the router
|
||||||
|
# advertisements will have the M and O bits set, so that the clients
|
||||||
|
# get addresses and configuration from DHCPv6, and the A bit reset, so the
|
||||||
|
# clients don't use SLAAC addresses.
|
||||||
|
#enable-ra
|
||||||
|
|
||||||
# Supply parameters for specified hosts using DHCP. There are lots
|
# Supply parameters for specified hosts using DHCP. There are lots
|
||||||
# of valid alternatives, so we will give examples of each. Note that
|
# of valid alternatives, so we will give examples of each. Note that
|
||||||
# IP addresses DO NOT have to be in the range given above, they just
|
# IP addresses DO NOT have to be in the range given above, they just
|
||||||
@@ -219,6 +262,12 @@
|
|||||||
# any machine with Ethernet address starting 11:22:33:
|
# any machine with Ethernet address starting 11:22:33:
|
||||||
#dhcp-host=11:22:33:*:*:*,set:red
|
#dhcp-host=11:22:33:*:*:*,set:red
|
||||||
|
|
||||||
|
# Give a fixed IPv6 address and name to client with
|
||||||
|
# DUID 00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2
|
||||||
|
# Note the MAC addresses CANNOT be used to identify DHCPv6 clients.
|
||||||
|
# Note also the they [] around the IPv6 address are obilgatory.
|
||||||
|
#dhcp-host=id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5]
|
||||||
|
|
||||||
# Ignore any clients which are not specified in dhcp-host lines
|
# Ignore any clients which are not specified in dhcp-host lines
|
||||||
# or /etc/ethers. Equivalent to ISC "deny unknown-clients".
|
# or /etc/ethers. Equivalent to ISC "deny unknown-clients".
|
||||||
# This relies on the special "known" tag which is set when
|
# This relies on the special "known" tag which is set when
|
||||||
@@ -270,6 +319,16 @@
|
|||||||
# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5
|
# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5
|
||||||
#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5
|
#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5
|
||||||
|
|
||||||
|
# Send DHCPv6 option. Note [] around IPv6 addresses.
|
||||||
|
#dhcp-option=option6:dns-server,[1234::77],[1234::88]
|
||||||
|
|
||||||
|
# Send DHCPv6 option for namservers as the machine running
|
||||||
|
# dnsmasq and another.
|
||||||
|
#dhcp-option=option6:dns-server,[::],[1234::88]
|
||||||
|
|
||||||
|
# Ask client to poll for option changes every six hours. (RFC4242)
|
||||||
|
#dhcp-option=option6:information-refresh-time,6h
|
||||||
|
|
||||||
# Set the NTP time server address to be the same machine as
|
# Set the NTP time server address to be the same machine as
|
||||||
# is running dnsmasq
|
# is running dnsmasq
|
||||||
#dhcp-option=42,0.0.0.0
|
#dhcp-option=42,0.0.0.0
|
||||||
@@ -421,7 +480,7 @@
|
|||||||
#tftp-no-blocksize
|
#tftp-no-blocksize
|
||||||
|
|
||||||
# Set the boot file name only when the "red" tag is set.
|
# Set the boot file name only when the "red" tag is set.
|
||||||
#dhcp-boot=net:red,pxelinux.red-net
|
#dhcp-boot=tag:red,pxelinux.red-net
|
||||||
|
|
||||||
# An example of dhcp-boot with an external TFTP server: the name and IP
|
# An example of dhcp-boot with an external TFTP server: the name and IP
|
||||||
# address of the server are given after the filename.
|
# address of the server are given after the filename.
|
||||||
@@ -466,7 +525,7 @@
|
|||||||
# If you want to disable negative caching, uncomment this.
|
# If you want to disable negative caching, uncomment this.
|
||||||
#no-negcache
|
#no-negcache
|
||||||
|
|
||||||
# Normally responses which come form /etc/hosts and the DHCP lease
|
# Normally responses which come from /etc/hosts and the DHCP lease
|
||||||
# file have Time-To-Live set as zero, which conventionally means
|
# file have Time-To-Live set as zero, which conventionally means
|
||||||
# do not cache further. If you are happy to trade lower load on the
|
# do not cache further. If you are happy to trade lower load on the
|
||||||
# server for potentially stale date, you can set a time-to-live (in
|
# server for potentially stale date, you can set a time-to-live (in
|
||||||
@@ -562,6 +621,6 @@
|
|||||||
# Log lots of extra information about DHCP transactions.
|
# Log lots of extra information about DHCP transactions.
|
||||||
#log-dhcp
|
#log-dhcp
|
||||||
|
|
||||||
# Include a another lot of configuration options.
|
# Include another lot of configuration options.
|
||||||
#conf-file=/etc/dnsmasq.more.conf
|
#conf-file=/etc/dnsmasq.more.conf
|
||||||
#conf-dir=/etc/dnsmasq.d
|
#conf-dir=/etc/dnsmasq.d
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
+301
-104
@@ -23,7 +23,7 @@ options. It includes a secure, read-only,
|
|||||||
TFTP server to allow net/PXE boot of DHCP hosts and also supports BOOTP.
|
TFTP server to allow net/PXE boot of DHCP hosts and also supports BOOTP.
|
||||||
.PP
|
.PP
|
||||||
Dnsmasq
|
Dnsmasq
|
||||||
supports IPv6 for DNS and TFTP, but not DHCP.
|
supports IPv6 for all functions and a minimal router-advertisement daemon.
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
Note that in general missing parameters are allowed and switch off
|
Note that in general missing parameters are allowed and switch off
|
||||||
functions, for instance "--pid-file" disables writing a PID file. On
|
functions, for instance "--pid-file" disables writing a PID file. On
|
||||||
@@ -71,6 +71,9 @@ maximum TTL will be given to clients instead of the true TTL value if it is
|
|||||||
lower. The true TTL value is however kept in the cache to avoid flooding
|
lower. The true TTL value is however kept in the cache to avoid flooding
|
||||||
the upstream DNS servers.
|
the upstream DNS servers.
|
||||||
.TP
|
.TP
|
||||||
|
.B --max-cache-ttl=<time>
|
||||||
|
Set a maximum TTL value for entries in the cache.
|
||||||
|
.TP
|
||||||
.B \-k, --keep-in-foreground
|
.B \-k, --keep-in-foreground
|
||||||
Do not go into the background at startup but otherwise run as
|
Do not go into the background at startup but otherwise run as
|
||||||
normal. This is intended for use when dnsmasq is run under daemontools
|
normal. This is intended for use when dnsmasq is run under daemontools
|
||||||
@@ -80,7 +83,9 @@ or launchd.
|
|||||||
Debug mode: don't fork to the background, don't write a pid file,
|
Debug mode: don't fork to the background, don't write a pid file,
|
||||||
don't change user id, generate a complete cache dump on receipt on
|
don't change user id, generate a complete cache dump on receipt on
|
||||||
SIGUSR1, log to stderr as well as syslog, don't fork new processes
|
SIGUSR1, log to stderr as well as syslog, don't fork new processes
|
||||||
to handle TCP queries.
|
to handle TCP queries. Note that this option is for use in debugging
|
||||||
|
only, to stop dnsmasq daemonising in production, use
|
||||||
|
.B -k.
|
||||||
.TP
|
.TP
|
||||||
.B \-q, --log-queries
|
.B \-q, --log-queries
|
||||||
Log the results of DNS queries handled by dnsmasq. Enable a full cache dump on receipt of SIGUSR1.
|
Log the results of DNS queries handled by dnsmasq. Enable a full cache dump on receipt of SIGUSR1.
|
||||||
@@ -204,6 +209,17 @@ running another nameserver (or another instance of dnsmasq) on the
|
|||||||
same machine. Setting this option also enables multiple instances of
|
same machine. Setting this option also enables multiple instances of
|
||||||
dnsmasq which provide DHCP service to run in the same machine.
|
dnsmasq which provide DHCP service to run in the same machine.
|
||||||
.TP
|
.TP
|
||||||
|
.B --bind-dynamic
|
||||||
|
Enable a network mode which is a hybrid between
|
||||||
|
.B --bind-interfaces
|
||||||
|
and the default. Dnsmasq binds the address of individual interfaces,
|
||||||
|
allowing multiple dnsmasq instances, but if new interfaces or
|
||||||
|
addresses appear, it automatically listens on those (subject to any
|
||||||
|
access-control configuration). This makes dynamically created
|
||||||
|
interfaces work in the same way as the default. Implementing this
|
||||||
|
option requires non-standard networking APIs and it is only available
|
||||||
|
under Linux. On other platforms it falls-back to --bind-interfaces mode.
|
||||||
|
.TP
|
||||||
.B \-y, --localise-queries
|
.B \-y, --localise-queries
|
||||||
Return answers to DNS queries from /etc/hosts which depend on the interface over which the query was
|
Return answers to DNS queries from /etc/hosts which depend on the interface over which the query was
|
||||||
received. If a name in /etc/hosts has more than one address associated with
|
received. If a name in /etc/hosts has more than one address associated with
|
||||||
@@ -260,11 +276,13 @@ time is the one used.
|
|||||||
Don't read /etc/resolv.conf. Get upstream servers only from the command
|
Don't read /etc/resolv.conf. Get upstream servers only from the command
|
||||||
line or the dnsmasq configuration file.
|
line or the dnsmasq configuration file.
|
||||||
.TP
|
.TP
|
||||||
.B \-1, --enable-dbus
|
.B \-1, --enable-dbus[=<service-name>]
|
||||||
Allow dnsmasq configuration to be updated via DBus method calls. The
|
Allow dnsmasq configuration to be updated via DBus method calls. The
|
||||||
configuration which can be changed is upstream DNS servers (and
|
configuration which can be changed is upstream DNS servers (and
|
||||||
corresponding domains) and cache clear. Requires that dnsmasq has
|
corresponding domains) and cache clear. Requires that dnsmasq has
|
||||||
been built with DBus support.
|
been built with DBus support. If the service name is given, dnsmasq
|
||||||
|
provides service at that name, rather than the default which is
|
||||||
|
.B uk.org.thekelleys.dnsmasq
|
||||||
.TP
|
.TP
|
||||||
.B \-o, --strict-order
|
.B \-o, --strict-order
|
||||||
By default, dnsmasq will send queries to any of the upstream servers
|
By default, dnsmasq will send queries to any of the upstream servers
|
||||||
@@ -416,6 +434,24 @@ zone files: the port, weight and priority numbers are in a different
|
|||||||
order. More than one SRV record for a given service/domain is allowed,
|
order. More than one SRV record for a given service/domain is allowed,
|
||||||
all that match are returned.
|
all that match are returned.
|
||||||
.TP
|
.TP
|
||||||
|
.B --host-record=<name>[,<name>....][<IPv4-address>],[<IPv6-address>]
|
||||||
|
Add A, AAAA and PTR records to the DNS. This adds one or more names to
|
||||||
|
the DNS with associated IPv4 (A) and IPv6 (AAAA) records. A name may
|
||||||
|
appear in more than one
|
||||||
|
.B host-record
|
||||||
|
and therefore be assigned more than one address. Only the first
|
||||||
|
address creates a PTR record linking the address to the name. This is
|
||||||
|
the same rule as is used reading hosts-files.
|
||||||
|
.B host-record
|
||||||
|
options are considered to be read before host-files, so a name
|
||||||
|
appearing there inhibits PTR-record creation if it appears in
|
||||||
|
hosts-file also. Unlike hosts-files, names are not expanded, even when
|
||||||
|
.B expand-hosts
|
||||||
|
is in effect. Short and long names may appear in the same
|
||||||
|
.B host-record,
|
||||||
|
eg.
|
||||||
|
.B --host-record=laptop,laptop.thekelleys.org,192.168.0.1,1234::100
|
||||||
|
.TP
|
||||||
.B \-Y, --txt-record=<name>[[,<text>],<text>]
|
.B \-Y, --txt-record=<name>[[,<text>],<text>]
|
||||||
Return a TXT DNS record. The value of TXT record is a set of strings,
|
Return a TXT DNS record. The value of TXT record is a set of strings,
|
||||||
so any number may be included, delimited by commas; use quotes to put
|
so any number may be included, delimited by commas; use quotes to put
|
||||||
@@ -432,10 +468,18 @@ Return an NAPTR DNS record, as specified in RFC3403.
|
|||||||
Return a CNAME record which indicates that <cname> is really
|
Return a CNAME record which indicates that <cname> is really
|
||||||
<target>. There are significant limitations on the target; it must be a
|
<target>. There are significant limitations on the target; it must be a
|
||||||
DNS name which is known to dnsmasq from /etc/hosts (or additional
|
DNS name which is known to dnsmasq from /etc/hosts (or additional
|
||||||
hosts files) or from DHCP. If the target does not satisfy this
|
hosts files), from DHCP or from another
|
||||||
|
.B --cname.
|
||||||
|
If the target does not satisfy this
|
||||||
criteria, the whole cname is ignored. The cname must be unique, but it
|
criteria, the whole cname is ignored. The cname must be unique, but it
|
||||||
is permissable to have more than one cname pointing to the same target.
|
is permissable to have more than one cname pointing to the same target.
|
||||||
.TP
|
.TP
|
||||||
|
.B --dns-rr=<name>,<RR-number>,[<hex data>]
|
||||||
|
Return an arbitrary DNS Resource Record. The number is the type of the
|
||||||
|
record (which is always in the C_IN class). The value of the record is
|
||||||
|
given by the hex data, which may be of the form 01:23:45 or 01 23 45 or
|
||||||
|
012345 or any mixture of these.
|
||||||
|
.TP
|
||||||
.B --interface-name=<name>,<interface>
|
.B --interface-name=<name>,<interface>
|
||||||
Return a DNS record associating the name with the primary address on
|
Return a DNS record associating the name with the primary address on
|
||||||
the given interface. This flag specifies an A record for the given
|
the given interface. This flag specifies an A record for the given
|
||||||
@@ -494,7 +538,10 @@ compiled in and the kernel must have conntrack support
|
|||||||
included and configured. This option cannot be combined with
|
included and configured. This option cannot be combined with
|
||||||
--query-port.
|
--query-port.
|
||||||
.TP
|
.TP
|
||||||
.B \-F, --dhcp-range=[interface:<interface>,][tag:<tag>[,tag:<tag>],][set:<tag],]<start-addr>,<end-addr>[,<netmask>[,<broadcast>]][,<lease time>]
|
.B \-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag],]<start-addr>[,<end-addr>][,<mode>][,<netmask>[,<broadcast>]][,<lease time>]
|
||||||
|
.TP
|
||||||
|
.B \-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag],]<start-IPv6addr>[,<end-IPv6addr>][,<mode>][,<prefix-len>][,<lease time>]
|
||||||
|
|
||||||
Enable the DHCP server. Addresses will be given out from the range
|
Enable the DHCP server. Addresses will be given out from the range
|
||||||
<start-addr> to <end-addr> and from statically defined addresses given
|
<start-addr> to <end-addr> and from statically defined addresses given
|
||||||
in
|
in
|
||||||
@@ -503,8 +550,12 @@ options. If the lease time is given, then leases
|
|||||||
will be given for that length of time. The lease time is in seconds,
|
will be given for that length of time. The lease time is in seconds,
|
||||||
or minutes (eg 45m) or hours (eg 1h) or "infinite". If not given,
|
or minutes (eg 45m) or hours (eg 1h) or "infinite". If not given,
|
||||||
the default lease time is one hour. The
|
the default lease time is one hour. The
|
||||||
minimum lease time is two minutes. This
|
minimum lease time is two minutes. For IPv6 ranges, the lease time
|
||||||
option may be repeated, with different addresses, to enable DHCP
|
maybe "deprecated"; this sets the preferred lifetime sent in a DHCP
|
||||||
|
lease or router advertisement to zero, which causes clients to use
|
||||||
|
other addresses, if available, for new connections as a prelude to renumbering.
|
||||||
|
|
||||||
|
This option may be repeated, with different addresses, to enable DHCP
|
||||||
service to more than one network. For directly connected networks (ie,
|
service to more than one network. For directly connected networks (ie,
|
||||||
networks on which the machine running dnsmasq has an interface) the
|
networks on which the machine running dnsmasq has an interface) the
|
||||||
netmask is optional: dnsmasq will determine it from the interface
|
netmask is optional: dnsmasq will determine it from the interface
|
||||||
@@ -515,20 +566,33 @@ C) of the network address. The broadcast address is
|
|||||||
always optional. It is always
|
always optional. It is always
|
||||||
allowed to have more than one dhcp-range in a single subnet.
|
allowed to have more than one dhcp-range in a single subnet.
|
||||||
|
|
||||||
|
For IPv6, the parameters are slightly different: instead of netmask
|
||||||
|
and broadcast address, there is an optional prefix length. If not
|
||||||
|
given, this defaults to 64. Unlike the IPv4 case, the prefix length is not
|
||||||
|
automatically derived from the interface configuration. The mimimum
|
||||||
|
size of the prefix length is 64.
|
||||||
|
|
||||||
The optional
|
The optional
|
||||||
.B set:<tag>
|
.B set:<tag>
|
||||||
sets an alphanumeric label which marks this network so that
|
sets an alphanumeric label which marks this network so that
|
||||||
dhcp options may be specified on a per-network basis.
|
dhcp options may be specified on a per-network basis.
|
||||||
When it is prefixed with 'tag:' instead, then its meaning changes from setting
|
When it is prefixed with 'tag:' instead, then its meaning changes from setting
|
||||||
a tag to matching it. Only one tag may be set, but more than one tag may be matched.
|
a tag to matching it. Only one tag may be set, but more than one tag
|
||||||
The end address may be replaced by the keyword
|
may be matched.
|
||||||
|
|
||||||
|
The optional <mode> keyword may be
|
||||||
.B static
|
.B static
|
||||||
which tells dnsmasq to enable DHCP for the network specified, but not
|
which tells dnsmasq to enable DHCP for the network specified, but not
|
||||||
to dynamically allocate IP addresses: only hosts which have static
|
to dynamically allocate IP addresses: only hosts which have static
|
||||||
addresses given via
|
addresses given via
|
||||||
.B dhcp-host
|
.B dhcp-host
|
||||||
or from /etc/ethers will be served. The end address may be replaced by
|
or from /etc/ethers will be served. A static-only subnet with address
|
||||||
the keyword
|
all zeros may be used as a "catch-all" address to enable replies to all
|
||||||
|
Information-request packets on a subnet which is provided with
|
||||||
|
stateless DHCPv6, ie
|
||||||
|
.B --dhcp=range=::,static
|
||||||
|
|
||||||
|
For IPv4, the <mode> may be
|
||||||
.B proxy
|
.B proxy
|
||||||
in which case dnsmasq will provide proxy-DHCP on the specified
|
in which case dnsmasq will provide proxy-DHCP on the specified
|
||||||
subnet. (See
|
subnet. (See
|
||||||
@@ -537,8 +601,42 @@ and
|
|||||||
.B pxe-service
|
.B pxe-service
|
||||||
for details.)
|
for details.)
|
||||||
|
|
||||||
The interface:<interface name> section is not normally used. See the
|
For IPv6, the mode may be some combination of
|
||||||
NOTES section for details of this.
|
.B ra-only, slaac, ra-names, ra-stateless.
|
||||||
|
|
||||||
|
.B ra-only
|
||||||
|
tells dnsmasq to offer Router Advertisement only on this subnet,
|
||||||
|
and not DHCP.
|
||||||
|
|
||||||
|
.B slaac
|
||||||
|
tells dnsmasq to offer Router Advertisement on this subnet and to set
|
||||||
|
the A bit in the router advertisement, so that the client will use
|
||||||
|
SLAAC addresses. When used with a DHCP range or static DHCP address
|
||||||
|
this results in the client having both a DHCP-assigned and a SLAAC
|
||||||
|
address.
|
||||||
|
|
||||||
|
.B ra-stateless
|
||||||
|
sends router advertisements with the O and A bits set, and provides a
|
||||||
|
stateless DHCP service. The client will use a SLAAC address, and use
|
||||||
|
DHCP for other configuration information.
|
||||||
|
|
||||||
|
.B ra-names
|
||||||
|
enables a mode
|
||||||
|
which gives DNS names to dual-stack hosts which do SLAAC for
|
||||||
|
IPv6. Dnsmasq uses the host's IPv4 lease to derive the name, network
|
||||||
|
segment and MAC address and assumes that the host will also have an
|
||||||
|
IPv6 address calculated using the SLAAC algorithm, on the same network
|
||||||
|
segment. The address is pinged, and if a reply is received, an AAAA
|
||||||
|
record is added to the DNS for this IPv6
|
||||||
|
address. Note that this is only happens for directly-connected
|
||||||
|
networks, (not one doing DHCP via a relay) and it will not work
|
||||||
|
if a host is using privacy extensions.
|
||||||
|
.B ra-names
|
||||||
|
can be combined with
|
||||||
|
.B ra-stateless
|
||||||
|
and
|
||||||
|
.B slaac.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-G, --dhcp-host=[<hwaddr>][,id:<client_id>|*][,set:<tag>][,<ipaddr>][,<hostname>][,<lease_time>][,ignore]
|
.B \-G, --dhcp-host=[<hwaddr>][,id:<client_id>|*][,set:<tag>][,<ipaddr>][,<hostname>][,<lease_time>][,ignore]
|
||||||
Specify per host parameters for the DHCP server. This allows a machine
|
Specify per host parameters for the DHCP server. This allows a machine
|
||||||
@@ -570,6 +668,12 @@ refers to the host with client identifier 01:02:03:04. It is also
|
|||||||
allowed to specify the client ID as text, like this:
|
allowed to specify the client ID as text, like this:
|
||||||
.B --dhcp-host=id:clientidastext,.....
|
.B --dhcp-host=id:clientidastext,.....
|
||||||
|
|
||||||
|
A single
|
||||||
|
.B dhcp-host
|
||||||
|
may contain an IPv4 address or an IPv6 address, or both. IPv6 addresses must be bracketed by square brackets thus:
|
||||||
|
.B --dhcp-host=laptop,[1234::56]
|
||||||
|
Note that in IPv6 DHCP, the hardware address is not normally available, so a client must be identified by client-id (called client DUID in IPv6-land) or hostname.
|
||||||
|
|
||||||
The special option id:* means "ignore any client-id
|
The special option id:* means "ignore any client-id
|
||||||
and use MAC addresses only." This is useful when a client presents a client-id sometimes
|
and use MAC addresses only." This is useful when a client presents a client-id sometimes
|
||||||
but not others.
|
but not others.
|
||||||
@@ -617,7 +721,7 @@ will only match a
|
|||||||
Token-Ring hardware address, since the ARP-address type for token ring
|
Token-Ring hardware address, since the ARP-address type for token ring
|
||||||
is 6.
|
is 6.
|
||||||
|
|
||||||
As a special case, it is possible to include more than one
|
As a special case, in DHCPv4, it is possible to include more than one
|
||||||
hardware address. eg:
|
hardware address. eg:
|
||||||
.B --dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2
|
.B --dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2
|
||||||
This allows an IP address to be associated with
|
This allows an IP address to be associated with
|
||||||
@@ -655,14 +759,14 @@ hostname or dotted-quad IP address. When read by dnsmasq these lines
|
|||||||
have exactly the same effect as
|
have exactly the same effect as
|
||||||
.B --dhcp-host
|
.B --dhcp-host
|
||||||
options containing the same information. /etc/ethers is re-read when
|
options containing the same information. /etc/ethers is re-read when
|
||||||
dnsmasq receives SIGHUP.
|
dnsmasq receives SIGHUP. IPv6 addresses are NOT read from /etc/ethers.
|
||||||
.TP
|
.TP
|
||||||
.B \-O, --dhcp-option=[tag:<tag>,[tag:<tag>,]][encap:<opt>,][vi-encap:<enterprise>,][vendor:[<vendor-class>],][<opt>|option:<opt-name>],[<value>[,<value>]]
|
.B \-O, --dhcp-option=[tag:<tag>,[tag:<tag>,]][encap:<opt>,][vi-encap:<enterprise>,][vendor:[<vendor-class>],][<opt>|option:<opt-name>|option6:<opt>|option6:<opt-name>],[<value>[,<value>]]
|
||||||
Specify different or extra options to DHCP clients. By default,
|
Specify different or extra options to DHCP clients. By default,
|
||||||
dnsmasq sends some standard options to DHCP clients, the netmask and
|
dnsmasq sends some standard options to DHCP clients, the netmask and
|
||||||
broadcast address are set to the same as the host running dnsmasq, and
|
broadcast address are set to the same as the host running dnsmasq, and
|
||||||
the DNS server and default route are set to the address of the machine
|
the DNS server and default route are set to the address of the machine
|
||||||
running dnsmasq. If the domain name option has been set, that is sent.
|
running dnsmasq. (Equivalent rules apply for IPv6.) If the domain name option has been set, that is sent.
|
||||||
This configuration allows these defaults to be overridden,
|
This configuration allows these defaults to be overridden,
|
||||||
or other options specified. The option, to be sent may be given as a
|
or other options specified. The option, to be sent may be given as a
|
||||||
decimal number or as "option:<option-name>" The option numbers are
|
decimal number or as "option:<option-name>" The option numbers are
|
||||||
@@ -677,7 +781,7 @@ and to set the time-server address to 192.168.0.4, do
|
|||||||
.B --dhcp-option = 42,192.168.0.4
|
.B --dhcp-option = 42,192.168.0.4
|
||||||
or
|
or
|
||||||
.B --dhcp-option = option:ntp-server, 192.168.0.4
|
.B --dhcp-option = option:ntp-server, 192.168.0.4
|
||||||
The special address 0.0.0.0 is taken to mean "the address of the
|
The special address 0.0.0.0 (or [::] for DHCPv6) is taken to mean "the address of the
|
||||||
machine running dnsmasq". Data types allowed are comma separated
|
machine running dnsmasq". Data types allowed are comma separated
|
||||||
dotted-quad IP addresses, a decimal number, colon-separated hex digits
|
dotted-quad IP addresses, a decimal number, colon-separated hex digits
|
||||||
and a text string. If the optional tags are given then
|
and a text string. If the optional tags are given then
|
||||||
@@ -689,6 +793,14 @@ to option 120 are handled as per RFC 3361. Dotted-quad IP addresses
|
|||||||
which are followed by a slash and then a netmask size are encoded as
|
which are followed by a slash and then a netmask size are encoded as
|
||||||
described in RFC 3442.
|
described in RFC 3442.
|
||||||
|
|
||||||
|
IPv6 options are specified using the
|
||||||
|
.B option6:
|
||||||
|
keyword, followed by the option number or option name. The IPv6 option
|
||||||
|
name space is disjoint from the IPv4 option name space. IPv6 addresses
|
||||||
|
in options must be bracketed with square brackets, eg.
|
||||||
|
.B --dhcp-option=option6:ntp-server,[1234::56]
|
||||||
|
|
||||||
|
|
||||||
Be careful: no checking is done that the correct type of data for the
|
Be careful: no checking is done that the correct type of data for the
|
||||||
option number is sent, it is quite possible to
|
option number is sent, it is quite possible to
|
||||||
persuade dnsmasq to generate illegal DHCP packets with injudicious use
|
persuade dnsmasq to generate illegal DHCP packets with injudicious use
|
||||||
@@ -704,7 +816,7 @@ literal string, use quotes. For instance when using option 66 to send
|
|||||||
a literal IP address as TFTP server name, it is necessary to do
|
a literal IP address as TFTP server name, it is necessary to do
|
||||||
.B --dhcp-option=66,"1.2.3.4"
|
.B --dhcp-option=66,"1.2.3.4"
|
||||||
|
|
||||||
Encapsulated Vendor-class options may also be specified using
|
Encapsulated Vendor-class options may also be specified (IPv4 only) using
|
||||||
--dhcp-option: for instance
|
--dhcp-option: for instance
|
||||||
.B --dhcp-option=vendor:PXEClient,1,0.0.0.0
|
.B --dhcp-option=vendor:PXEClient,1,0.0.0.0
|
||||||
sends the encapsulated vendor
|
sends the encapsulated vendor
|
||||||
@@ -716,9 +828,9 @@ for selecting encapsulated options in preference to any sent by the
|
|||||||
client. It is
|
client. It is
|
||||||
possible to omit the vendorclass completely;
|
possible to omit the vendorclass completely;
|
||||||
.B --dhcp-option=vendor:,1,0.0.0.0
|
.B --dhcp-option=vendor:,1,0.0.0.0
|
||||||
in which case the encapsulated option is always sent.
|
in which case the encapsulated option is always sent.
|
||||||
|
|
||||||
Options may be encapsulated within other options: for instance
|
Options may be encapsulated (IPv4 only) within other options: for instance
|
||||||
.B --dhcp-option=encap:175, 190, "iscsi-client0"
|
.B --dhcp-option=encap:175, 190, "iscsi-client0"
|
||||||
will send option 175, within which is the option 190. If multiple
|
will send option 175, within which is the option 190. If multiple
|
||||||
options are given which are encapsulated with the same option number
|
options are given which are encapsulated with the same option number
|
||||||
@@ -729,8 +841,9 @@ The final variant on encapsulated options is "Vendor-Identifying
|
|||||||
Vendor Options" as specified by RFC3925. These are denoted like this:
|
Vendor Options" as specified by RFC3925. These are denoted like this:
|
||||||
.B --dhcp-option=vi-encap:2, 10, "text"
|
.B --dhcp-option=vi-encap:2, 10, "text"
|
||||||
The number in the vi-encap: section is the IANA enterprise number
|
The number in the vi-encap: section is the IANA enterprise number
|
||||||
used to identify this option.
|
used to identify this option. This form of encapsulation is supported
|
||||||
|
in IPv6.
|
||||||
|
|
||||||
The address 0.0.0.0 is not treated specially in
|
The address 0.0.0.0 is not treated specially in
|
||||||
encapsulated options.
|
encapsulated options.
|
||||||
.TP
|
.TP
|
||||||
@@ -742,14 +855,14 @@ not ask for it in the parameter request list. This is sometimes
|
|||||||
needed, for example when sending options to PXELinux.
|
needed, for example when sending options to PXELinux.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-no-override
|
.B --dhcp-no-override
|
||||||
Disable re-use of the DHCP servername and filename fields as extra
|
(IPv4 only) Disable re-use of the DHCP servername and filename fields as extra
|
||||||
option space. If it can, dnsmasq moves the boot server and filename
|
option space. If it can, dnsmasq moves the boot server and filename
|
||||||
information (from dhcp-boot) out of their dedicated fields into
|
information (from dhcp-boot) out of their dedicated fields into
|
||||||
DHCP options. This make extra space available in the DHCP packet for
|
DHCP options. This make extra space available in the DHCP packet for
|
||||||
options but can, rarely, confuse old or broken clients. This flag
|
options but can, rarely, confuse old or broken clients. This flag
|
||||||
forces "simple and safe" behaviour to avoid problems in such a case.
|
forces "simple and safe" behaviour to avoid problems in such a case.
|
||||||
.TP
|
.TP
|
||||||
.B \-U, --dhcp-vendorclass=set:<tag>,<vendor-class>
|
.B \-U, --dhcp-vendorclass=set:<tag>,[enterprise:<IANA-enterprise number>,]<vendor-class>
|
||||||
Map from a vendor-class string to a tag. Most DHCP clients provide a
|
Map from a vendor-class string to a tag. Most DHCP clients provide a
|
||||||
"vendor class" which represents, in some sense, the type of host. This option
|
"vendor class" which represents, in some sense, the type of host. This option
|
||||||
maps vendor classes to tags, so that DHCP options may be selectively delivered
|
maps vendor classes to tags, so that DHCP options may be selectively delivered
|
||||||
@@ -759,7 +872,13 @@ will allow options to be set only for HP printers like so:
|
|||||||
.B --dhcp-option=tag:printers,3,192.168.4.4
|
.B --dhcp-option=tag:printers,3,192.168.4.4
|
||||||
The vendor-class string is
|
The vendor-class string is
|
||||||
substring matched against the vendor-class supplied by the client, to
|
substring matched against the vendor-class supplied by the client, to
|
||||||
allow fuzzy matching. The set: prefix is optional but allowed for consistency.
|
allow fuzzy matching. The set: prefix is optional but allowed for
|
||||||
|
consistency.
|
||||||
|
|
||||||
|
Note that in IPv6 only, vendorclasses are namespaced with an
|
||||||
|
IANA-allocated enterprise number. This is given with enterprise:
|
||||||
|
keyword and specifies that only vendorclasses matching the specified
|
||||||
|
number should be searched.
|
||||||
.TP
|
.TP
|
||||||
.B \-j, --dhcp-userclass=set:<tag>,<user-class>
|
.B \-j, --dhcp-userclass=set:<tag>,<user-class>
|
||||||
Map from a user-class string to a tag (with substring
|
Map from a user-class string to a tag (with substring
|
||||||
@@ -771,7 +890,7 @@ this to set a different printer server for hosts in the class
|
|||||||
"accounts" than for hosts in the class "engineering".
|
"accounts" than for hosts in the class "engineering".
|
||||||
.TP
|
.TP
|
||||||
.B \-4, --dhcp-mac=set:<tag>,<MAC address>
|
.B \-4, --dhcp-mac=set:<tag>,<MAC address>
|
||||||
Map from a MAC address to a tag. The MAC address may include
|
(IPv4 only) Map from a MAC address to a tag. The MAC address may include
|
||||||
wildcards. For example
|
wildcards. For example
|
||||||
.B --dhcp-mac=set:3com,01:34:23:*:*:*
|
.B --dhcp-mac=set:3com,01:34:23:*:*:*
|
||||||
will set the tag "3com" for any host whose MAC address matches the pattern.
|
will set the tag "3com" for any host whose MAC address matches the pattern.
|
||||||
@@ -781,13 +900,16 @@ Map from RFC3046 relay agent options to tags. This data may
|
|||||||
be provided by DHCP relay agents. The circuit-id or remote-id is
|
be provided by DHCP relay agents. The circuit-id or remote-id is
|
||||||
normally given as colon-separated hex, but is also allowed to be a
|
normally given as colon-separated hex, but is also allowed to be a
|
||||||
simple string. If an exact match is achieved between the circuit or
|
simple string. If an exact match is achieved between the circuit or
|
||||||
agent ID and one provided by a relay agent, the tag is set.
|
agent ID and one provided by a relay agent, the tag is set.
|
||||||
|
|
||||||
|
.B dhcp-remoteid
|
||||||
|
(but not dhcp-circuitid) is supported in IPv6.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-subscrid=set:<tag>,<subscriber-id>
|
.B --dhcp-subscrid=set:<tag>,<subscriber-id>
|
||||||
Map from RFC3993 subscriber-id relay agent options to tags.
|
(IPv4 and IPv6) Map from RFC3993 subscriber-id relay agent options to tags.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-proxy[=<ip addr>]......
|
.B --dhcp-proxy[=<ip addr>]......
|
||||||
A normal DHCP relay agent is only used to forward the initial parts of
|
(IPv4 only) A normal DHCP relay agent is only used to forward the initial parts of
|
||||||
a DHCP interaction to the DHCP server. Once a client is configured, it
|
a DHCP interaction to the DHCP server. Once a client is configured, it
|
||||||
communicates directly with the server. This is undesirable if the
|
communicates directly with the server. This is undesirable if the
|
||||||
relay agent is addding extra information to the DHCP packets, such as
|
relay agent is addding extra information to the DHCP packets, such as
|
||||||
@@ -847,7 +969,7 @@ dhcp-host configuration in dnsmasq and the contents of /etc/hosts and
|
|||||||
/etc/ethers.
|
/etc/ethers.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-generate-names=tag:<tag>[,tag:<tag>]
|
.B --dhcp-generate-names=tag:<tag>[,tag:<tag>]
|
||||||
Generate a name for DHCP clients which do not otherwise have one,
|
(IPv4 only) Generate a name for DHCP clients which do not otherwise have one,
|
||||||
using the MAC address expressed in hex, seperated by dashes. Note that
|
using the MAC address expressed in hex, seperated by dashes. Note that
|
||||||
if a host provides a name, it will be used by preference to this,
|
if a host provides a name, it will be used by preference to this,
|
||||||
unless
|
unless
|
||||||
@@ -855,14 +977,14 @@ unless
|
|||||||
is set.
|
is set.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-broadcast[=tag:<tag>[,tag:<tag>]]
|
.B --dhcp-broadcast[=tag:<tag>[,tag:<tag>]]
|
||||||
When all the given tags appear in the tag set, always use broadcast to
|
(IPv4 only) When all the given tags appear in the tag set, always use broadcast to
|
||||||
communicate with the host when it is unconfigured. It is permissible
|
communicate with the host when it is unconfigured. It is permissible
|
||||||
to supply no tags, in which case this is unconditional. Most DHCP clients which
|
to supply no tags, in which case this is unconditional. Most DHCP clients which
|
||||||
need broadcast replies set a flag in their requests so that this
|
need broadcast replies set a flag in their requests so that this
|
||||||
happens automatically, some old BOOTP clients do not.
|
happens automatically, some old BOOTP clients do not.
|
||||||
.TP
|
.TP
|
||||||
.B \-M, --dhcp-boot=[tag:<tag>,]<filename>,[<servername>[,<server address>|<tftp_servername>]]
|
.B \-M, --dhcp-boot=[tag:<tag>,]<filename>,[<servername>[,<server address>|<tftp_servername>]]
|
||||||
Set BOOTP options to be returned by the DHCP server. Server name and
|
(IPv4 only) Set BOOTP options to be returned by the DHCP server. Server name and
|
||||||
address are optional: if not provided, the name is left empty, and the
|
address are optional: if not provided, the name is left empty, and the
|
||||||
address set to the address of the machine running dnsmasq. If dnsmasq
|
address set to the address of the machine running dnsmasq. If dnsmasq
|
||||||
is providing a TFTP service (see
|
is providing a TFTP service (see
|
||||||
@@ -888,7 +1010,7 @@ address, and setting this flag enables this mode. Note that in the
|
|||||||
sequential mode, clients which allow a lease to expire are much more
|
sequential mode, clients which allow a lease to expire are much more
|
||||||
likely to move IP address; for this reason it should not be generally used.
|
likely to move IP address; for this reason it should not be generally used.
|
||||||
.TP
|
.TP
|
||||||
.B --pxe-service=[tag:<tag>,]<CSA>,<menu text>[,<basename>|<bootservicetype>][,<server address>]
|
.B --pxe-service=[tag:<tag>,]<CSA>,<menu text>[,<basename>|<bootservicetype>][,<server address>|<server_name>]
|
||||||
Most uses of PXE boot-ROMS simply allow the PXE
|
Most uses of PXE boot-ROMS simply allow the PXE
|
||||||
system to obtain an IP address and then download the file specified by
|
system to obtain an IP address and then download the file specified by
|
||||||
.B dhcp-boot
|
.B dhcp-boot
|
||||||
@@ -904,17 +1026,19 @@ parameter after the menu text may be a file name, in which case dnsmasq acts as
|
|||||||
boot server and directs the PXE client to download the file by TFTP,
|
boot server and directs the PXE client to download the file by TFTP,
|
||||||
either from itself (
|
either from itself (
|
||||||
.B enable-tftp
|
.B enable-tftp
|
||||||
must be set for this to work) or another TFTP server if the final IP
|
must be set for this to work) or another TFTP server if the final server
|
||||||
address is given.
|
address/name is given.
|
||||||
Note that the "layer"
|
Note that the "layer"
|
||||||
suffix (normally ".0") is supplied by PXE, and should not be added to
|
suffix (normally ".0") is supplied by PXE, and should not be added to
|
||||||
the basename. If an integer boot service type, rather than a basename
|
the basename. If an integer boot service type, rather than a basename
|
||||||
is given, then the PXE client will search for a
|
is given, then the PXE client will search for a
|
||||||
suitable boot service for that type on the network. This search may be done
|
suitable boot service for that type on the network. This search may be done
|
||||||
by broadcast, or direct to a server if its IP address is provided.
|
by broadcast, or direct to a server if its IP address/name is provided.
|
||||||
If no boot service type or filename is provided (or a boot service type of 0 is specified)
|
If no boot service type or filename is provided (or a boot service type of 0 is specified)
|
||||||
then the menu entry will abort the net boot procedure and
|
then the menu entry will abort the net boot procedure and
|
||||||
continue booting from local media.
|
continue booting from local media. The server address can be given as a domain
|
||||||
|
name which is looked up in /etc/hosts. This name can be associated in
|
||||||
|
/etc/hosts with multiple IP addresses, which are used round-robin.
|
||||||
.TP
|
.TP
|
||||||
.B --pxe-prompt=[tag:<tag>,]<prompt>[,<timeout>]
|
.B --pxe-prompt=[tag:<tag>,]<prompt>[,<timeout>]
|
||||||
Setting this provides a prompt to be displayed after PXE boot. If the
|
Setting this provides a prompt to be displayed after PXE boot. If the
|
||||||
@@ -947,7 +1071,7 @@ create thousands of leases and use lots of memory in the dnsmasq
|
|||||||
process.
|
process.
|
||||||
.TP
|
.TP
|
||||||
.B \-K, --dhcp-authoritative
|
.B \-K, --dhcp-authoritative
|
||||||
Should be set when dnsmasq is definitely the only DHCP server on a network.
|
(IPv4 only) Should be set when dnsmasq is definitely the only DHCP server on a network.
|
||||||
It changes the behaviour from strict RFC compliance so that DHCP requests on
|
It changes the behaviour from strict RFC compliance so that DHCP requests on
|
||||||
unknown leases from unknown hosts are not ignored. This allows new hosts
|
unknown leases from unknown hosts are not ignored. This allows new hosts
|
||||||
to get a lease without a tedious timeout under all circumstances. It also
|
to get a lease without a tedious timeout under all circumstances. It also
|
||||||
@@ -955,7 +1079,7 @@ allows dnsmasq to rebuild its lease database without each client needing to
|
|||||||
reacquire a lease, if the database is lost.
|
reacquire a lease, if the database is lost.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-alternate-port[=<server port>[,<client port>]]
|
.B --dhcp-alternate-port[=<server port>[,<client port>]]
|
||||||
Change the ports used for DHCP from the default. If this option is
|
(IPv4 only) Change the ports used for DHCP from the default. If this option is
|
||||||
given alone, without arguments, it changes the ports used for DHCP
|
given alone, without arguments, it changes the ports used for DHCP
|
||||||
from 67 and 68 to 1067 and 1068. If a single argument is given, that
|
from 67 and 68 to 1067 and 1068. If a single argument is given, that
|
||||||
port number is used for the server and the port number plus one used
|
port number is used for the server and the port number plus one used
|
||||||
@@ -963,7 +1087,7 @@ for the client. Finally, two port numbers allows arbitrary
|
|||||||
specification of both server and client ports for DHCP.
|
specification of both server and client ports for DHCP.
|
||||||
.TP
|
.TP
|
||||||
.B \-3, --bootp-dynamic[=<network-id>[,<network-id>]]
|
.B \-3, --bootp-dynamic[=<network-id>[,<network-id>]]
|
||||||
Enable dynamic allocation of IP addresses to BOOTP clients. Use this
|
(IPv4 only) Enable dynamic allocation of IP addresses to BOOTP clients. Use this
|
||||||
with care, since each address allocated to a BOOTP client is leased
|
with care, since each address allocated to a BOOTP client is leased
|
||||||
forever, and therefore becomes permanently unavailable for re-use by
|
forever, and therefore becomes permanently unavailable for re-use by
|
||||||
other hosts. if this is given without tags, then it unconditionally
|
other hosts. if this is given without tags, then it unconditionally
|
||||||
@@ -971,7 +1095,7 @@ enables dynamic allocation. With tags, only when the tags are all
|
|||||||
set. It may be repeated with different tag sets.
|
set. It may be repeated with different tag sets.
|
||||||
.TP
|
.TP
|
||||||
.B \-5, --no-ping
|
.B \-5, --no-ping
|
||||||
By default, the DHCP server will attempt to ensure that an address in
|
(IPv4 only) By default, the DHCP server will attempt to ensure that an address in
|
||||||
not in use before allocating it to a host. It does this by sending an
|
not in use before allocating it to a host. It does this by sending an
|
||||||
ICMP echo request (aka "ping") to the address in question. If it gets
|
ICMP echo request (aka "ping") to the address in question. If it gets
|
||||||
a reply, then the address must already be in use, and another is
|
a reply, then the address must already be in use, and another is
|
||||||
@@ -984,13 +1108,24 @@ the tags used to determine them.
|
|||||||
.B \-l, --dhcp-leasefile=<path>
|
.B \-l, --dhcp-leasefile=<path>
|
||||||
Use the specified file to store DHCP lease information.
|
Use the specified file to store DHCP lease information.
|
||||||
.TP
|
.TP
|
||||||
|
.B --dhcp-duid=<enterprise-id>,<uid>
|
||||||
|
(IPv6 only) Specify the server persistent UID which the DHCPv6 server
|
||||||
|
will use. This option is not normally required as dnsmasq creates a
|
||||||
|
DUID automatically when it is first needed. When given, this option
|
||||||
|
provides dnsmasq the data required to create a DUID-EN type DUID. Note
|
||||||
|
that once set, the DUID is stored in the lease database, so to change between DUID-EN and
|
||||||
|
automatically created DUIDs or vice-versa, the lease database must be
|
||||||
|
re-intialised. The enterprise-id is assigned by IANA, and the uid is a
|
||||||
|
string of hex octets unique to a particular device.
|
||||||
|
.TP
|
||||||
.B \-6 --dhcp-script=<path>
|
.B \-6 --dhcp-script=<path>
|
||||||
Whenever a new DHCP lease is created, or an old one destroyed, the
|
Whenever a new DHCP lease is created, or an old one destroyed, or a
|
||||||
|
TFTP file transfer completes, the
|
||||||
executable specified by this option is run. <path>
|
executable specified by this option is run. <path>
|
||||||
must be an absolute pathname, no PATH search occurs.
|
must be an absolute pathname, no PATH search occurs.
|
||||||
The arguments to the process
|
The arguments to the process
|
||||||
are "add", "old" or "del", the MAC
|
are "add", "old" or "del", the MAC
|
||||||
address of the host, the IP address, and the hostname,
|
address of the host (or DUID for IPv6) , the IP address, and the hostname,
|
||||||
if known. "add" means a lease has been created, "del" means it has
|
if known. "add" means a lease has been created, "del" means it has
|
||||||
been destroyed, "old" is a notification of an existing lease when
|
been destroyed, "old" is a notification of an existing lease when
|
||||||
dnsmasq starts or a change to MAC address or hostname of an existing
|
dnsmasq starts or a change to MAC address or hostname of an existing
|
||||||
@@ -1001,21 +1136,17 @@ token ring. The process is run as root (assuming that dnsmasq was originally run
|
|||||||
root) even if dnsmasq is configured to change UID to an unprivileged user.
|
root) even if dnsmasq is configured to change UID to an unprivileged user.
|
||||||
|
|
||||||
The environment is inherited from the invoker of dnsmasq, with some or
|
The environment is inherited from the invoker of dnsmasq, with some or
|
||||||
all of the following variables added.
|
all of the following variables added
|
||||||
|
|
||||||
DNSMASQ_CLIENT_ID if the host provided a client-id.
|
For both IPv4 and IPv6:
|
||||||
|
|
||||||
DNSMASQ_DOMAIN if the fully-qualified domain name of the host is
|
DNSMASQ_DOMAIN if the fully-qualified domain name of the host is
|
||||||
known, this is set to the domain part. (Note that the hostname passed
|
known, this is set to the domain part. (Note that the hostname passed
|
||||||
to the script as an argument is never fully-qualified.)
|
to the script as an argument is never fully-qualified.)
|
||||||
|
|
||||||
If the client provides vendor-class, hostname or user-class,
|
If the client provides a hostname, DNSMASQ_SUPPLIED_HOSTNAME
|
||||||
these are provided in DNSMASQ_VENDOR_CLASS
|
|
||||||
DNSMASQ_SUPPLIED_HOSTNAME and
|
If the client provides user-classes, DNSMASQ_USER_CLASS0..DNSMASQ_USER_CLASSn
|
||||||
DNSMASQ_USER_CLASS0..DNSMASQ_USER_CLASSn variables, but only for
|
|
||||||
"add" actions or "old" actions when a host resumes an existing lease,
|
|
||||||
since these data are not held in dnsmasq's lease
|
|
||||||
database.
|
|
||||||
|
|
||||||
If dnsmasq was compiled with HAVE_BROKEN_RTC, then
|
If dnsmasq was compiled with HAVE_BROKEN_RTC, then
|
||||||
the length of the lease (in seconds) is stored in
|
the length of the lease (in seconds) is stored in
|
||||||
@@ -1039,6 +1170,38 @@ is known.
|
|||||||
DNSMASQ_TAGS contains all the tags set during the
|
DNSMASQ_TAGS contains all the tags set during the
|
||||||
DHCP transaction, separated by spaces.
|
DHCP transaction, separated by spaces.
|
||||||
|
|
||||||
|
DNSMASQ_LOG_DHCP is set if
|
||||||
|
.B --log-dhcp
|
||||||
|
is in effect.
|
||||||
|
|
||||||
|
For IPv4 only:
|
||||||
|
|
||||||
|
DNSMASQ_CLIENT_ID if the host provided a client-id.
|
||||||
|
|
||||||
|
If the client provides vendor-class, DNSMASQ_VENDOR_CLASS.
|
||||||
|
|
||||||
|
For IPv6 only:
|
||||||
|
|
||||||
|
If the client provides vendor-class, DNSMASQ_VENDOR_CLASS_ID,
|
||||||
|
containing the IANA enterprise id for the class, and
|
||||||
|
DNSMASQ_VENDOR_CLASS0..DNSMASQ_VENDOR_CLASSn for the data.
|
||||||
|
|
||||||
|
DNSMASQ_SERVER_DUID containing the DUID of the server: this is the same for
|
||||||
|
every call to the script.
|
||||||
|
|
||||||
|
DNSMASQ_IAID containing the IAID for the lease. If the lease is a
|
||||||
|
temporary allocation, this is prefixed to 'T'.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Note that the supplied hostname, vendorclass and userclass data is
|
||||||
|
only supplied for
|
||||||
|
"add" actions or "old" actions when a host resumes an existing lease,
|
||||||
|
since these data are not held in dnsmasq's lease
|
||||||
|
database.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All file descriptors are
|
All file descriptors are
|
||||||
closed except stdin, stdout and stderr which are open to /dev/null
|
closed except stdin, stdout and stderr which are open to /dev/null
|
||||||
(except in debug mode).
|
(except in debug mode).
|
||||||
@@ -1057,9 +1220,66 @@ all existing leases as they are read from the lease file. Expired
|
|||||||
leases will be called with "del" and others with "old". When dnsmasq
|
leases will be called with "del" and others with "old". When dnsmasq
|
||||||
receives a HUP signal, the script will be invoked for existing leases
|
receives a HUP signal, the script will be invoked for existing leases
|
||||||
with an "old " event.
|
with an "old " event.
|
||||||
|
|
||||||
|
|
||||||
|
There are two further actions which may appear as the first argument
|
||||||
|
to the script, "init" and "tftp". More may be added in the future, so
|
||||||
|
scripts should be written to ignore unknown actions. "init" is
|
||||||
|
described below in
|
||||||
|
.B --leasefile-ro
|
||||||
|
The "tftp" action is invoked when a TFTP file transfer completes: the
|
||||||
|
arguments are the file size in bytes, the address to which the file
|
||||||
|
was sent, and the complete pathname of the file.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B --dhcp-luascript=<path>
|
||||||
|
Specify a script written in Lua, to be run when leases are created,
|
||||||
|
destroyed or changed. To use this option, dnsmasq must be compiled
|
||||||
|
with the correct support. The Lua interpreter is intialised once, when
|
||||||
|
dnsmasq starts, so that global variables persist between lease
|
||||||
|
events. The Lua code must define a
|
||||||
|
.B lease
|
||||||
|
function, and may provide
|
||||||
|
.B init
|
||||||
|
and
|
||||||
|
.B shutdown
|
||||||
|
functions, which are called, without arguments when dnsmasq starts up
|
||||||
|
and terminates. It may also provide a
|
||||||
|
.B tftp
|
||||||
|
function.
|
||||||
|
|
||||||
|
The
|
||||||
|
.B lease
|
||||||
|
function receives the information detailed in
|
||||||
|
.B --dhcp-script.
|
||||||
|
It gets two arguments, firstly the action, which is a string
|
||||||
|
containing, "add", "old" or "del", and secondly a table of tag value
|
||||||
|
pairs. The tags mostly correspond to the environment variables
|
||||||
|
detailed above, for instance the tag "domain" holds the same data as
|
||||||
|
the environment variable DNSMASQ_DOMAIN. There are a few extra tags
|
||||||
|
which hold the data supplied as arguments to
|
||||||
|
.B --dhcp-script.
|
||||||
|
These are
|
||||||
|
.B mac_address, ip_address
|
||||||
|
and
|
||||||
|
.B hostname
|
||||||
|
for IPv4, and
|
||||||
|
.B client_duid, ip_address
|
||||||
|
and
|
||||||
|
.B hostname
|
||||||
|
for IPv6.
|
||||||
|
|
||||||
|
The
|
||||||
|
.B tftp
|
||||||
|
function is called in the same way as the lease function, and the
|
||||||
|
table holds the tags
|
||||||
|
.B destination_address,
|
||||||
|
.B file_name
|
||||||
|
and
|
||||||
|
.B file_size.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-scriptuser
|
.B --dhcp-scriptuser
|
||||||
Specify the user as which to run the lease-change script. This defaults to root, but can be changed to another user using this flag.
|
Specify the user as which to run the lease-change script or Lua script. This defaults to root, but can be changed to another user using this flag.
|
||||||
.TP
|
.TP
|
||||||
.B \-9, --leasefile-ro
|
.B \-9, --leasefile-ro
|
||||||
Completely suppress use of the lease database file. The file will not
|
Completely suppress use of the lease database file. The file will not
|
||||||
@@ -1142,12 +1362,29 @@ added into dnsmasq's DNS view. This flag suppresses that behaviour,
|
|||||||
this is useful, for instance, to allow Windows clients to update
|
this is useful, for instance, to allow Windows clients to update
|
||||||
Active Directory servers. See RFC 4702 for details.
|
Active Directory servers. See RFC 4702 for details.
|
||||||
.TP
|
.TP
|
||||||
.B --enable-tftp[=<interface>]
|
.B --enable-ra
|
||||||
|
Enable dnsmasq's IPv6 Router Advertisement feature. DHCPv6 doesn't
|
||||||
|
handle complete network configuration in the same way as DHCPv4. Router
|
||||||
|
discovery and (possibly) prefix discovery for autonomous address
|
||||||
|
creation are handled by a different protocol. When DHCP is in use,
|
||||||
|
only a subset of this is needed, and dnsmasq can handle it, using
|
||||||
|
existing DHCP configuration to provide most data. When RA is enabled,
|
||||||
|
dnsmasq will advertise a prefix for each dhcp-range, with default
|
||||||
|
router and recursive DNS server as the relevant link-local address on
|
||||||
|
the machine running dnsmasq. By default, he "managed address" bits are set, and
|
||||||
|
the "use SLAAC" bit is reset. This can be changed for individual
|
||||||
|
subnets with the mode keywords described in
|
||||||
|
.B --dhcp-range.
|
||||||
|
RFC6106 DNS parameters are included in the advertisements. By default,
|
||||||
|
the relevant link-local address of the machine running dnsmasq is sent
|
||||||
|
as recursive DNS server. If provided, the DHCPv6 options dns-server and
|
||||||
|
domain-search are used for RDNSS and DNSSL.
|
||||||
|
.TP
|
||||||
|
.B --enable-tftp
|
||||||
Enable the TFTP server function. This is deliberately limited to that
|
Enable the TFTP server function. This is deliberately limited to that
|
||||||
needed to net-boot a client. Only reading is allowed; the tsize and
|
needed to net-boot a client. Only reading is allowed; the tsize and
|
||||||
blksize extensions are supported (tsize is only supported in octet
|
blksize extensions are supported (tsize is only supported in octet
|
||||||
mode). See NOTES section for use of the interface argument.
|
mode).
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B --tftp-root=<directory>[,<interface>]
|
.B --tftp-root=<directory>[,<interface>]
|
||||||
Look for files to transfer using TFTP relative to the given
|
Look for files to transfer using TFTP relative to the given
|
||||||
@@ -1175,6 +1412,12 @@ are accessible. It is not recommended to run dnsmasq as root with TFTP
|
|||||||
enabled, and certainly not without specifying --tftp-root. Doing so
|
enabled, and certainly not without specifying --tftp-root. Doing so
|
||||||
can expose any world-readable file on the server to any host on the net.
|
can expose any world-readable file on the server to any host on the net.
|
||||||
.TP
|
.TP
|
||||||
|
.B --tftp-lowercase
|
||||||
|
Convert filenames in TFTP requests to all lowercase. This is useful
|
||||||
|
for requests from Windows machines, which have case-insensitive
|
||||||
|
filesystems and tend to play fast-and-loose with case in filenames.
|
||||||
|
Note that dnsmasq's tftp server always converts "\\" to "/" in filenames.
|
||||||
|
.TP
|
||||||
.B --tftp-max=<connections>
|
.B --tftp-max=<connections>
|
||||||
Set the maximum number of concurrent TFTP connections allowed. This
|
Set the maximum number of concurrent TFTP connections allowed. This
|
||||||
defaults to 50. When serving a large number of TFTP connections,
|
defaults to 50. When serving a large number of TFTP connections,
|
||||||
@@ -1405,52 +1648,6 @@ parameter in a BOOTP request is used as a tag,
|
|||||||
as is the tag "bootp", allowing some control over the options returned to
|
as is the tag "bootp", allowing some control over the options returned to
|
||||||
different classes of hosts.
|
different classes of hosts.
|
||||||
|
|
||||||
.B dhcp-range
|
|
||||||
may have an interface name supplied as
|
|
||||||
"interface:<interface-name>". The semantics if this are as follows:
|
|
||||||
For DHCP, if any other dhcp-range exists _without_ an interface name,
|
|
||||||
then the interface name is ignored and and dnsmasq behaves as if the
|
|
||||||
interface parts did not exist, otherwise DHCP is only provided to
|
|
||||||
interfaces mentioned in dhcp-range
|
|
||||||
declarations. For DNS, if there are no
|
|
||||||
.B --interface
|
|
||||||
or
|
|
||||||
.B --listen-address
|
|
||||||
flags, behaviour is unchanged by the interface part. If either of
|
|
||||||
these flags are present, the interfaces mentioned in
|
|
||||||
dhcp-ranges are added to the set which get DNS service.
|
|
||||||
|
|
||||||
Similarly,
|
|
||||||
.B enable-tftp
|
|
||||||
may take an interface name, which enables TFTP only for a particular
|
|
||||||
interface, ignoring
|
|
||||||
.B --interface
|
|
||||||
or
|
|
||||||
.B --listen-address
|
|
||||||
flags. In addition
|
|
||||||
.B --tftp-secure
|
|
||||||
and
|
|
||||||
.B --tftp-unique-root
|
|
||||||
and
|
|
||||||
.B --tftp-no-blocksize
|
|
||||||
are ignored for requests from such interfaces. (A
|
|
||||||
.B --tftp-root
|
|
||||||
directive giving a root path and an interface should be
|
|
||||||
provided too.)
|
|
||||||
|
|
||||||
These rules may seem odd at first sight, but they
|
|
||||||
allow a single line of the form "dhcp-range=interface:virt0,192.168.0.4,192.168.0.200"
|
|
||||||
to be added to dnsmasq configuration which then supplies
|
|
||||||
DHCP and DNS services to that interface, without affecting
|
|
||||||
what services are supplied to other interfaces and irrespective of
|
|
||||||
the existance or lack of "interface=<interface>"
|
|
||||||
lines elsewhere in the dnsmasq configuration.
|
|
||||||
"enable-tftp=virt0" and "tftp-root=<root>,virt0" do the same job for TFTP.
|
|
||||||
The idea is
|
|
||||||
that such a line can be added automatically by libvirt
|
|
||||||
or equivalent systems, without disturbing any manual
|
|
||||||
configuration.
|
|
||||||
|
|
||||||
.SH EXIT CODES
|
.SH EXIT CODES
|
||||||
.PP
|
.PP
|
||||||
0 - Dnsmasq successfully forked into the background, or terminated
|
0 - Dnsmasq successfully forked into the background, or terminated
|
||||||
|
|||||||
+359
-147
@@ -22,7 +22,8 @@ peut être configuré pour envoyer n'importe quel option DHCP.
|
|||||||
Il inclut un serveur TFTP sécurisé en lecture seule permettant le démarrage via
|
Il inclut un serveur TFTP sécurisé en lecture seule permettant le démarrage via
|
||||||
le réseau/PXE de clients DHCP et supporte également le protocole BOOTP.
|
le réseau/PXE de clients DHCP et supporte également le protocole BOOTP.
|
||||||
.PP
|
.PP
|
||||||
Dnsmasq supporte IPv6 pour le DNS et TFTP mais pas pour le DHCP.
|
Dnsmasq supporte IPv6 et contient un démon minimaliste capable de faire des
|
||||||
|
annonces routeurs ("router-advertisements").
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
Notes : Il est possible d'utiliser des options sans leur donner de paramètre.
|
Notes : Il est possible d'utiliser des options sans leur donner de paramètre.
|
||||||
Dans ce cas, la fonction correspondante sera désactivée. Par exemple
|
Dans ce cas, la fonction correspondante sera désactivée. Par exemple
|
||||||
@@ -231,6 +232,18 @@ autre serveur de nom (ou une autre instance de Dnsmasq) tourne sur la même
|
|||||||
machine. Utiliser cette option permet également d'avoir plusieurs instances de
|
machine. Utiliser cette option permet également d'avoir plusieurs instances de
|
||||||
Dnsmasq fournissant un service DHCP sur la même machine.
|
Dnsmasq fournissant un service DHCP sur la même machine.
|
||||||
.TP
|
.TP
|
||||||
|
.B --bind-dynamic
|
||||||
|
Autorise un mode réseau intermédiaire entre
|
||||||
|
.B --bind-interfaces
|
||||||
|
et le mode par défaut. Dnsmasq s'associe à une seule interface, ce qui permet
|
||||||
|
plusieurs instances de dnsmasq, mais si une interface ou adresse apparaissent,
|
||||||
|
il se mettra automatiquement à écouter sur celles-ci (les règles de contrôle
|
||||||
|
d'accès s'appliquent).
|
||||||
|
De fait, les interfaces créées dynamiquement fonctionnent de la même façon que
|
||||||
|
dans le comportement par défaut. Ce fonctionnement nécessite des APIs réseau
|
||||||
|
non standard et n'est disponible que sous Linux. Sur les autres plateformes,
|
||||||
|
le fonctionnement est celui du mode --bind-interfaces.
|
||||||
|
.TP
|
||||||
.B \-y, --localise-queries
|
.B \-y, --localise-queries
|
||||||
Retourne des réponses aux requêtes DNS dépendantes de l'interface sur laquelle
|
Retourne des réponses aux requêtes DNS dépendantes de l'interface sur laquelle
|
||||||
la requête a été reçue, à partir du fichier /etc/hosts. Si un nom dans
|
la requête a été reçue, à partir du fichier /etc/hosts. Si un nom dans
|
||||||
@@ -492,6 +505,27 @@ dans un ordre différents. Pour un service/domaine donné, plus d'un
|
|||||||
enregistrement SRV est autorisé et tous les enregistrements qui coïncident sont
|
enregistrement SRV est autorisé et tous les enregistrements qui coïncident sont
|
||||||
retournés dans la réponse.
|
retournés dans la réponse.
|
||||||
.TP
|
.TP
|
||||||
|
.B --host-record=<nom>[,<nom>....][<adresse IPv4>],[<adresse IPv6>]
|
||||||
|
Ajoute des enregistrements A, AAAA et PTR dans le DNS. Ceci permet d'ajouter
|
||||||
|
un ou plusieurs noms dans le DNS et de les associer à des enregistrements IPv4
|
||||||
|
(A) ou IPv6 (AAAA). Un nom peut apparaître dans plus d'une entrée
|
||||||
|
.B host-record
|
||||||
|
et de fait être associé à plus d'une adresse. Seule la première entrée créée
|
||||||
|
l'enregistrement PTR associée au nom. Ceci correspond à la même règle que celle
|
||||||
|
utilisée lors de la lecture du fichier hosts.
|
||||||
|
Les options
|
||||||
|
.B host-record
|
||||||
|
sont considérées lues avant le fichier hosts, ainsi un nom apparaissant dans
|
||||||
|
une option host-record et dans le fichier hosts n'aura pas d'enregistrement
|
||||||
|
PTR associé à l'entrée dans le fichier hosts. A l'inverse du fichier hosts, les
|
||||||
|
noms ne sont pas étendus, même lorsque l'option
|
||||||
|
.B expand-hosts
|
||||||
|
est activée. Les noms longs et les noms courts peuvent apparaitre dans la même
|
||||||
|
entrée
|
||||||
|
.B host-record,
|
||||||
|
c-à-d
|
||||||
|
.B --host-record=laptop,laptop.thekelleys.org,192.168.0.1,1234::100
|
||||||
|
.TP
|
||||||
.B \-Y, --txt-record=<nom>[[,<texte>],<texte>]
|
.B \-Y, --txt-record=<nom>[[,<texte>],<texte>]
|
||||||
Définit un enregistrement DNS de type TXT. La valeur de l'enregistrement TXT est
|
Définit un enregistrement DNS de type TXT. La valeur de l'enregistrement TXT est
|
||||||
un ensemble de chaînes de caractères, donc un nombre variable de chaînes de
|
un ensemble de chaînes de caractères, donc un nombre variable de chaînes de
|
||||||
@@ -510,9 +544,17 @@ Retourne un enregistrement de type NAPTR, tel que spécifié dans le RFC3403.
|
|||||||
Retourne un enregistrement de type CNAME qui indique que <cname> est en
|
Retourne un enregistrement de type CNAME qui indique que <cname> est en
|
||||||
réalité <cible>. Il existe des contraintes significatives sur la valeur
|
réalité <cible>. Il existe des contraintes significatives sur la valeur
|
||||||
de cible; il doit s'agir d'un nom DNS qui est connu de dnsmasq via /etc/hosts
|
de cible; il doit s'agir d'un nom DNS qui est connu de dnsmasq via /etc/hosts
|
||||||
(ou un fichier hôtes additionnel) ou via DHCP. Si une cible ne satisfait
|
(ou un fichier hôtes additionnel), ou via DHCP, ou par un autre
|
||||||
pas ces critères, le CNAME est ignoré. Le CNAME doit être unique, mais
|
.B --cname.
|
||||||
il est autorisé d'avoir plus d'un CNAME pointant vers la même cible.
|
Si une cible ne satisfait pas ces critères, le CNAME est ignoré. Le CNAME
|
||||||
|
doit être unique, mais il est autorisé d'avoir plus d'un CNAME pointant
|
||||||
|
vers la même cible.
|
||||||
|
.TP
|
||||||
|
.B --dns-rr=<nom>,<numéro-RR>,[<données hexadécimales>]
|
||||||
|
Retourne un enregistrement DNS arbitraire. Le numéro correspond au type
|
||||||
|
d'enregistrement (qui est toujours de la classe C_IN). La valeur de
|
||||||
|
l'enregistrement est donnée dans les données hexadécimales, qui peuvent
|
||||||
|
être de la forme 01:23:45, 01 23 45,+012345 ou n'importe quelle combinaison.
|
||||||
.TP
|
.TP
|
||||||
.B --interface-name=<nom>,<interface>
|
.B --interface-name=<nom>,<interface>
|
||||||
Définit un entregistrement DNS associant le nom avec l'adresse primaire sur
|
Définit un entregistrement DNS associant le nom avec l'adresse primaire sur
|
||||||
@@ -577,9 +619,11 @@ l'ayant déclenché, ce qui est pratique pour la gestion de la bande passante
|
|||||||
(accounting) et le filtrage (firewall). Dnsmasq doit pour cela être compilé
|
(accounting) et le filtrage (firewall). Dnsmasq doit pour cela être compilé
|
||||||
avec le support conntrack, le noyau doit également inclure conntrack et être
|
avec le support conntrack, le noyau doit également inclure conntrack et être
|
||||||
configuré pour cela. Cette option ne peut pas être combinée avec
|
configuré pour cela. Cette option ne peut pas être combinée avec
|
||||||
--query-port.
|
--query-port.
|
||||||
.TP
|
.TP
|
||||||
.B \-F, --dhcp-range=[interface:<interface>,][tag:<label>[,tag:<label>],][set:<label],]<adresse de début>,<adresse de fin>[,<masque de réseau>[,<broadcast>]][,<durée de bail>]
|
.B \-F, --dhcp-range=[tag:<label>[,tag:<label>],][set:<label>],]<adresse de début>[,<adresse de fin>][,<mode>][,<masque de réseau>[,<broadcast>]][,<durée de bail>]
|
||||||
|
.TP
|
||||||
|
.B \-F, --dhcp-range=[tag:<label>[,tag:<label>],][set:<label>],]<addresse IPv6 de début>[,<adresse IPv6 de fin>][,<mode>][,<longueur de préfixe>][,<durée de bail>]
|
||||||
Active le serveur DHCP. Les adresses seront données dans la plage comprise entre
|
Active le serveur DHCP. Les adresses seront données dans la plage comprise entre
|
||||||
<adresse de début> et <adresse de fin> et à partir des adresses définies
|
<adresse de début> et <adresse de fin> et à partir des adresses définies
|
||||||
statiquement dans l'option
|
statiquement dans l'option
|
||||||
@@ -590,6 +634,13 @@ en heures (exemple : 1h) ou être la chaine de caractère "infinite" pour une
|
|||||||
durée indéterminée. Si aucune valeur n'est donnée, une durée de bail par défaut
|
durée indéterminée. Si aucune valeur n'est donnée, une durée de bail par défaut
|
||||||
de une heure est appliquée. La valeur minimum pour un bail DHCP est de 2
|
de une heure est appliquée. La valeur minimum pour un bail DHCP est de 2
|
||||||
minutes.
|
minutes.
|
||||||
|
|
||||||
|
Pour les plages IPv6, la durée de bail peut-être égale au mot-clef "deprecated"
|
||||||
|
(obsolète); Cela positionne la durée de vie préférée envoyée dans les baux DHCP
|
||||||
|
ou les annonces routeurs à zéro, ce qui incite les clients à utiliser d'autres
|
||||||
|
adresses autant que possible, pour toute nouvelle connexion, en préalable à
|
||||||
|
la renumérotation.
|
||||||
|
|
||||||
Cette option peut être répétée, avec différentes adresses,
|
Cette option peut être répétée, avec différentes adresses,
|
||||||
pour activer le service DHCP sur plus d'un réseau. Pour des réseaux directement
|
pour activer le service DHCP sur plus d'un réseau. Pour des réseaux directement
|
||||||
connectés (c'est-à-dire des réseaux dans lesquels la machine sur laquelle tourne
|
connectés (c'est-à-dire des réseaux dans lesquels la machine sur laquelle tourne
|
||||||
@@ -604,6 +655,14 @@ est toujours optionnelle.
|
|||||||
|
|
||||||
Il est toujours possible d'avoir plus d'une plage DHCP pour un même
|
Il est toujours possible d'avoir plus d'une plage DHCP pour un même
|
||||||
sous-réseau.
|
sous-réseau.
|
||||||
|
|
||||||
|
Pour IPv6, les paramètres sont légèrement différents : au lieu d'un masque de
|
||||||
|
réseau et d'une adresse de broadcast, il existe une longueur de préfixe
|
||||||
|
optionnelle. Si elle est omise, la valeur par défaut est 64. À la différence
|
||||||
|
d'IPv4, la longueur de préfixe n'est pas automatiquement déduite de la
|
||||||
|
configuration de l'interface. La taille minimale pour la longueur de préfixe
|
||||||
|
est 64.
|
||||||
|
|
||||||
L'identifiant de label optionnel
|
L'identifiant de label optionnel
|
||||||
.B set:<label>
|
.B set:<label>
|
||||||
fournie une étiquette alphanumérique qui identifie ce réseau, afin de permettre
|
fournie une étiquette alphanumérique qui identifie ce réseau, afin de permettre
|
||||||
@@ -612,15 +671,15 @@ Lorsque préfixé par 'tag:', la signification change, et au lieu de définir un
|
|||||||
label, il définit le label pour laquelle la règle s'applique. Un seul label peut-
|
label, il définit le label pour laquelle la règle s'applique. Un seul label peut-
|
||||||
être défini mais plusieurs labels peuvent coïncider.
|
être défini mais plusieurs labels peuvent coïncider.
|
||||||
|
|
||||||
L'adresse de fin peut être remplacée par le mot-clef
|
Le mot clef optionnel <mode> peut être égal à
|
||||||
.B static
|
.B static
|
||||||
("statique") qui indique à Dnsmasq d'activer le service DHCP pour le réseau
|
("statique") ce qui indique à Dnsmasq d'activer le service DHCP pour le réseau
|
||||||
spécifié, mais de ne pas activer l'allocation dynamique d'adresses IP : Seuls
|
spécifié, mais de ne pas activer l'allocation dynamique d'adresses IP : Seuls
|
||||||
les hôtes possédant des adresses IP statiques fournies via
|
les hôtes possédant des adresses IP statiques fournies via
|
||||||
.B dhcp-host
|
.B dhcp-host
|
||||||
ou présentes dans le fichier /etc/ethers seront alors servis par le DHCP.
|
ou présentes dans le fichier /etc/ethers seront alors servis par le DHCP.
|
||||||
|
|
||||||
L'adresse de fin peut-être remplacée par le mot-clef
|
Pour IPv4, le <mode> peut est égal à
|
||||||
.B proxy
|
.B proxy
|
||||||
, auquel cas Dnsmasq fournira un service de DHCP proxy pour le sous-réseau
|
, auquel cas Dnsmasq fournira un service de DHCP proxy pour le sous-réseau
|
||||||
spécifié. (voir
|
spécifié. (voir
|
||||||
@@ -629,8 +688,43 @@ et
|
|||||||
.B pxe-service
|
.B pxe-service
|
||||||
pour plus de détails).
|
pour plus de détails).
|
||||||
|
|
||||||
La section interface:<nom d'interface> n'est normalement pas utilisée. Se
|
Pour IPv6, le mode peut-être une combinaison des valeurs
|
||||||
référer aux indications de la section NOTES pour plus de détail à ce sujet.
|
.B ra-only, slaac, ra-names, ra-stateless.
|
||||||
|
|
||||||
|
.B ra-only
|
||||||
|
indique à dnsmasq de n'effectuer que des annonces de routeur (Router
|
||||||
|
Advertisement, RA) sur ce sous-réseau, et de ne pas faire de DHCP.
|
||||||
|
|
||||||
|
.B slaac
|
||||||
|
indique à dnsmasq d'effectuer des annonces de routeur sur ce sous-réseau
|
||||||
|
et de positionner dans celles-ci le bit A, afin que les clients utilisent
|
||||||
|
des adresses SLAAC. Lorsqu'utilisé conjointement avec une plage DHCP ou des
|
||||||
|
affectations statiques d'adresses DHCP, les clients disposeront à la fois
|
||||||
|
d'adresses DHCP assignées et d'adresses SLAAC.
|
||||||
|
|
||||||
|
.B ra-stateless
|
||||||
|
indique à dnsmasq d'effectuer des annonces de routeur avec les bits 0 et A
|
||||||
|
positionnés, et de fournir un service DHCP sans état ("stateless"). Les clients
|
||||||
|
utiliseront des adresses SLAAC, et utiliseront DHCP pour toutes les autres
|
||||||
|
informations de configuration.
|
||||||
|
|
||||||
|
.B ra-names
|
||||||
|
active un mode qui fourni des noms DNS aux hôtes fonctionnant en double pile
|
||||||
|
("dual stack") et configurés pour faire du SLAAC en IPv6. Dnsmasq utilise le
|
||||||
|
bail IPv4 de l'hôte afin de dériver le nom, le segment de réseau et l'adresse
|
||||||
|
MAC et assume que l'hôte disposera d'une adresse IPv6 calculée via l'algorithme
|
||||||
|
SLAAC, sur le même segment de réseau. Un ping est envoyé à l'adresse, et si une
|
||||||
|
réponse est obtenue, un enregistrement AAAA est rajouté dans le DNS pour cette
|
||||||
|
adresse IPv6. Veuillez-noter que cela n'arrive que pour les réseaux directement
|
||||||
|
connectés (et non ceux pour lesquels DHCP se fait via relai), et ne
|
||||||
|
fonctionnera pas si un hôte utilise les "extensions de vie privée"
|
||||||
|
("privacy extensions").
|
||||||
|
.B ra-names
|
||||||
|
peut-être combiné avec
|
||||||
|
.B ra-stateless
|
||||||
|
et
|
||||||
|
.B slaac.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-G, --dhcp-host=[<adresse matérielle>][,id:<identifiant client>|*][,set:<label>][,<adresse IP>][,<nom d'hôte>][,<durée de bail>][,ignore]
|
.B \-G, --dhcp-host=[<adresse matérielle>][,id:<identifiant client>|*][,set:<label>][,<adresse IP>][,<nom d'hôte>][,<durée de bail>][,ignore]
|
||||||
Spécifie les paramètres DHCP relatifs à un hôte. Cela permet à une machine
|
Spécifie les paramètres DHCP relatifs à un hôte. Cela permet à une machine
|
||||||
@@ -663,6 +757,15 @@ spécifier l'identifiant client sous la forme d'une chaîne de caractères, comm
|
|||||||
ceci :
|
ceci :
|
||||||
.B --dhcp-host=id:identifiantclientsousformedechaine,.....
|
.B --dhcp-host=id:identifiantclientsousformedechaine,.....
|
||||||
|
|
||||||
|
Un seul
|
||||||
|
.B dhcp-host
|
||||||
|
peut contenir une adresse IPv4, une adresse IPv6, ou les deux en même temps.
|
||||||
|
Les adresses IPv6 doivent-être mises entre crochets comme suit :
|
||||||
|
.B --dhcp-host=laptop,[1234::56]
|
||||||
|
A noter que pour le DHCP IPv6, l'adresse matérielle n'est en principe pas
|
||||||
|
disponible, aussi un client doit-être identifié par un identifiant de client
|
||||||
|
(appellé "DUID client") ou un nom d'hôte.
|
||||||
|
|
||||||
L'option spéciale id:* signifie : "ignorer tout identifiant client et n'utiliser
|
L'option spéciale id:* signifie : "ignorer tout identifiant client et n'utiliser
|
||||||
que l'adresse matérielle". Cela est utile lorsqu'un client présente un
|
que l'adresse matérielle". Cela est utile lorsqu'un client présente un
|
||||||
identifiant client mais pas les autres.
|
identifiant client mais pas les autres.
|
||||||
@@ -709,7 +812,7 @@ ARP en les précédant du type ARP (en Hexadécimal) et de "-". Ainsi
|
|||||||
coïncidera uniquement avec des adresses matérielles Token-Ring, puisque le type
|
coïncidera uniquement avec des adresses matérielles Token-Ring, puisque le type
|
||||||
ARP pour une adresse Token-Ring est 6.
|
ARP pour une adresse Token-Ring est 6.
|
||||||
|
|
||||||
Un cas spécial correspond à l'inclusion d'une ou plusieurs adresses
|
Un cas spécial, pour IPv4, correspond à l'inclusion d'une ou plusieurs adresses
|
||||||
matérielles, c-à-d :
|
matérielles, c-à-d :
|
||||||
.B --dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2.
|
.B --dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2.
|
||||||
Cela permet à une adresse IP d'être associé à plusieurs adresses
|
Cela permet à une adresse IP d'être associé à plusieurs adresses
|
||||||
@@ -750,22 +853,22 @@ une adresse IP sous la forme de 4 chiffres séparés par des points. Lorsque lu
|
|||||||
par Dnsmasq, ces lignes ont exactement le même effet que l'option
|
par Dnsmasq, ces lignes ont exactement le même effet que l'option
|
||||||
.B --dhcp-host
|
.B --dhcp-host
|
||||||
contenant les mêmes informations. /etc/ethers est relu à la réception d'un
|
contenant les mêmes informations. /etc/ethers est relu à la réception d'un
|
||||||
signal SIGHUP par Dnsmasq.
|
signal SIGHUP par Dnsmasq. Les adresses IPv6 ne sont PAS lues dans /etc/ethers.
|
||||||
.TP
|
.TP
|
||||||
.B \-O, --dhcp-option=[tag:<label>,[tag:<label>]][encap:<option>,][vi-encap:<entreprise>,][vendor:[<classe_vendeur>],][<option>|option:<nom d'option>],[<valeur>[,<valeur>]]
|
.B \-O, --dhcp-option=[tag:<label>,[tag:<label>]][encap:<option>,][vi-encap:<entreprise>,][vendor:[<classe_vendeur>],][<option>|option:<nom d'option>|option6:<option>|option6:<nom d'option>],[<valeur>[,<valeur>]]
|
||||||
Spécifie des options différentes ou supplémentaires pour des clients DHCP. Par
|
Spécifie des options différentes ou supplémentaires pour des clients DHCP. Par
|
||||||
défaut, Dnsmasq envoie un ensemble standard d'options aux clients DHCP : le
|
défaut, Dnsmasq envoie un ensemble standard d'options aux clients DHCP : le
|
||||||
masque de réseau et l'adresse de broadcast sont les mêmes que pour l'hôte
|
masque de réseau et l'adresse de broadcast sont les mêmes que pour l'hôte
|
||||||
sur lequel tourne Dnsmasq, et le serveur DNS ainsi que la route par défaut
|
sur lequel tourne Dnsmasq, et le serveur DNS ainsi que la route par défaut
|
||||||
prennent comme valeur l'adresse de la machine sur laquelle tourne Dnsmasq. Si
|
prennent comme valeur l'adresse de la machine sur laquelle tourne Dnsmasq.
|
||||||
une option de nom de domaine a été définie, son contenu est transmis. Cette
|
(Des règles équivalentes s'appliquent en IPv6). Si une option de nom de domaine
|
||||||
option de configuration permet de changer toutes ces valeurs par défaut, ou de
|
a été définie, son contenu est transmis. Cette option de configuration permet
|
||||||
spécifier d'autres options. L'option DHCP à transmettre peut être fournie sous
|
de changer toutes ces valeurs par défaut, ou de spécifier d'autres options.
|
||||||
forme d'un nombre décimal ou sous la forme "option:<nom d'option>". Les nombres
|
L'option DHCP à transmettre peut être fournie sous forme d'un nombre décimal
|
||||||
correspondants aux options sont définis dans la RFC2132 et suivants. Les noms
|
ou sous la forme "option:<nom d'option>". Les nombres correspondants aux options
|
||||||
d'options connus par Dnsmasq peuvent être obtenus via "Dnsmasq --help dhcp".
|
sont définis dans la RFC2132 et suivants. Les noms d'options connus par Dnsmasq
|
||||||
Par exemple, pour définir la route par défaut à 192.168.4.4, il est possible de
|
peuvent être obtenus via "Dnsmasq --help dhcp". Par exemple, pour définir la
|
||||||
faire
|
route par défaut à 192.168.4.4, il est possible de faire
|
||||||
.B --dhcp-option=3,192.168.4.4
|
.B --dhcp-option=3,192.168.4.4
|
||||||
ou
|
ou
|
||||||
.B --dhcp-option = option:router, 192.168.4.4
|
.B --dhcp-option = option:router, 192.168.4.4
|
||||||
@@ -788,6 +891,13 @@ de l'option 120 sont traités conforméments à la RFC 3361. Les adresses IP sou
|
|||||||
forme de 4 chiffres séparés par des points suivies par une barre montante "/",
|
forme de 4 chiffres séparés par des points suivies par une barre montante "/",
|
||||||
puis une taille de masque sont encodés conforméments à la RFC 3442.
|
puis une taille de masque sont encodés conforméments à la RFC 3442.
|
||||||
|
|
||||||
|
Les options IPv6 sont fournies en utilisant le mot-clef
|
||||||
|
.B option6:
|
||||||
|
suivi par le numéro d'option ou le nom d'option. L'espace de nommage des options
|
||||||
|
IPv6 est disjint de l'espace de nommage des options IPv4. Les adresses IPv6
|
||||||
|
en option doivent être entourées de crochets, comme par exemple :
|
||||||
|
.B --dhcp-option=option6:ntp-server,[1234::56]
|
||||||
|
|
||||||
Attention : aucun test n'étant fait pour vérifier que des données d'un type
|
Attention : aucun test n'étant fait pour vérifier que des données d'un type
|
||||||
adéquat sont envoyées pour un numéro d'option donné, il est tout à fait possible
|
adéquat sont envoyées pour un numéro d'option donné, il est tout à fait possible
|
||||||
de persuader Dnsmasq de générer des paquets DHCP illégaux par une utilisation
|
de persuader Dnsmasq de générer des paquets DHCP illégaux par une utilisation
|
||||||
@@ -806,8 +916,8 @@ d'une chaîne de caractères comme nom de serveur TFTP, il est nécessaire de fa
|
|||||||
comme suit :
|
comme suit :
|
||||||
.B --dhcp-option=66,"1.2.3.4"
|
.B --dhcp-option=66,"1.2.3.4"
|
||||||
|
|
||||||
Les options encapsulées de classes de vendeurs peuvent-être aussi spécifiées en
|
Les options encapsulées de classes de vendeurs peuvent-être aussi spécifiées
|
||||||
utilisant
|
(pour IPv4 seulement) en utilisant
|
||||||
.B --dhcp-option
|
.B --dhcp-option
|
||||||
: par exemple
|
: par exemple
|
||||||
.B --dhcp-option=vendor:PXEClient,1,0.0.0.0
|
.B --dhcp-option=vendor:PXEClient,1,0.0.0.0
|
||||||
@@ -823,7 +933,7 @@ par le client. Il est possible d'omettre complètement une classe de vendeur :
|
|||||||
.B --dhcp-option=vendor:,1,0.0.0.0
|
.B --dhcp-option=vendor:,1,0.0.0.0
|
||||||
Dans ce cas l'option encapsulée est toujours envoyée.
|
Dans ce cas l'option encapsulée est toujours envoyée.
|
||||||
|
|
||||||
Les options peuvent-être encapsulées au sein d'autres options :
|
En IPv4, les options peuvent-être encapsulées au sein d'autres options :
|
||||||
par exemple
|
par exemple
|
||||||
.B --dhcp-option=encap:175, 190, "iscsi-client0"
|
.B --dhcp-option=encap:175, 190, "iscsi-client0"
|
||||||
enverra l'option 175, au sein de laquelle se trouve l'option 190.
|
enverra l'option 175, au sein de laquelle se trouve l'option 190.
|
||||||
@@ -836,7 +946,8 @@ identifiant le vendeur" ("Vendor-Identifying Vendor Options") telle que
|
|||||||
décrite dans le RFC3925. Celles-ci sont spécifiées comme suit :
|
décrite dans le RFC3925. Celles-ci sont spécifiées comme suit :
|
||||||
.B --dhcp-option=vi-encap:2, 10, "text"
|
.B --dhcp-option=vi-encap:2, 10, "text"
|
||||||
Le numéro dans la section vi-encap: est le numéro IANA de l'entreprise servant
|
Le numéro dans la section vi-encap: est le numéro IANA de l'entreprise servant
|
||||||
à identifier cette option.
|
à identifier cette option. Cette forme d'encapsulation est également supportée
|
||||||
|
en IPv6.
|
||||||
|
|
||||||
L'adresse 0.0.0.0 n'est pas traitée de manière particulière lorsque fournie dans
|
L'adresse 0.0.0.0 n'est pas traitée de manière particulière lorsque fournie dans
|
||||||
une option encapsulée.
|
une option encapsulée.
|
||||||
@@ -849,8 +960,8 @@ dans la liste de paramêtres requis. Cela est parfois nécessaire, par exemple l
|
|||||||
de la fourniture d'options à PXELinux.
|
de la fourniture d'options à PXELinux.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-no-override
|
.B --dhcp-no-override
|
||||||
Désactive la réutilisation des champs DHCP nom de serveur et nom de
|
(IPv4 seulement) Désactive la réutilisation des champs DHCP nom de serveur et
|
||||||
fichier comme espace supplémentaire pour les options. Si cela est
|
nom de fichier comme espace supplémentaire pour les options. Si cela est
|
||||||
possible, dnsmasq déplace les informations sur le serveur de démarrage
|
possible, dnsmasq déplace les informations sur le serveur de démarrage
|
||||||
et le nom de fichier (fournis par 'dhcp-boot') en dehors des champs
|
et le nom de fichier (fournis par 'dhcp-boot') en dehors des champs
|
||||||
dédiés à cet usage dans les options DHCP. Cet espace supplémentaire est
|
dédiés à cet usage dans les options DHCP. Cet espace supplémentaire est
|
||||||
@@ -859,7 +970,8 @@ quelques rares cas, perturber des clients vieux ou défectueux. Cette
|
|||||||
option force le comportement à l'utilisation des valeurs "simples et sûres"
|
option force le comportement à l'utilisation des valeurs "simples et sûres"
|
||||||
afin d'éviter des problèmes dans de tels cas.
|
afin d'éviter des problèmes dans de tels cas.
|
||||||
.TP
|
.TP
|
||||||
.B \-U, --dhcp-vendorclass=set:<label>,<classe de vendeur>
|
.B \-U, --dhcp-vendorclass=set:<label>,[enterprise:<numéro IANA d'enterprise>,]<classe de vendeur>
|
||||||
|
|
||||||
Associe une chaîne de classe de vendeur à un label. La plupart
|
Associe une chaîne de classe de vendeur à un label. La plupart
|
||||||
des clients DHCP fournissent une "classe de vendeur" ("vendor class") qui
|
des clients DHCP fournissent une "classe de vendeur" ("vendor class") qui
|
||||||
représente, d'une certaine façon, le type d'hôte. Cette option associe des
|
représente, d'une certaine façon, le type d'hôte. Cette option associe des
|
||||||
@@ -875,6 +987,11 @@ en temps que sous-chaîne de caractères au sein de la classe de vendeur fournie
|
|||||||
par le client, de façon à permettre la recherche d'un sous-ensemble de la chaîne
|
par le client, de façon à permettre la recherche d'un sous-ensemble de la chaîne
|
||||||
de caractères ("fuzzy matching"). Le préfixe set: est optionnel mais autorisé
|
de caractères ("fuzzy matching"). Le préfixe set: est optionnel mais autorisé
|
||||||
afin de conserver une certaine homogénéité.
|
afin de conserver une certaine homogénéité.
|
||||||
|
|
||||||
|
Notez qu'en IPv6 (et seulement en IPv6), les noms de classes de vendeurs
|
||||||
|
sont dans un espace de nom associé au numéro attribué à l'entreprise par
|
||||||
|
l'IANA. Ce numéro est fourni par le biais du mot-clef enterprise: et seules
|
||||||
|
les classes de vendeurs associées au numéro spécifié seront cherchées.
|
||||||
.TP
|
.TP
|
||||||
.B \-j, --dhcp-userclass=set:<label>,<classe utilisateur>
|
.B \-j, --dhcp-userclass=set:<label>,<classe utilisateur>
|
||||||
Associe une chaîne de classe d'utilisateur à un label (effectue la
|
Associe une chaîne de classe d'utilisateur à un label (effectue la
|
||||||
@@ -887,7 +1004,7 @@ d'impression différent pour les hôtes de la classe "comptes" et ceux de la
|
|||||||
classe "ingénierie".
|
classe "ingénierie".
|
||||||
.TP
|
.TP
|
||||||
.B \-4, --dhcp-mac=set:<label>,<adresse MAC>
|
.B \-4, --dhcp-mac=set:<label>,<adresse MAC>
|
||||||
Associe une adresse matérielle (MAC) à un label. L'adresse
|
(IPv4 uniquement) Associe une adresse matérielle (MAC) à un label. L'adresse
|
||||||
matérielle peut inclure des jokers. Par exemple
|
matérielle peut inclure des jokers. Par exemple
|
||||||
.B --dhcp-mac=set:3com,01:34:23:*:*:*
|
.B --dhcp-mac=set:3com,01:34:23:*:*:*
|
||||||
permet de définir le label "3com" pour n'importe quel hôte dont l'adresse
|
permet de définir le label "3com" pour n'importe quel hôte dont l'adresse
|
||||||
@@ -901,16 +1018,19 @@ chaîne de valeurs hexadécimales séparées par des ":", mais il est également
|
|||||||
possible qu'elle le soit sous la forme d'une simple chaîne de caractères. Si
|
possible qu'elle le soit sous la forme d'une simple chaîne de caractères. Si
|
||||||
l'identifiant de circuit ou d'agent correspond exactement à celui fourni par le
|
l'identifiant de circuit ou d'agent correspond exactement à celui fourni par le
|
||||||
relais DHCP, alors le label est apposé.
|
relais DHCP, alors le label est apposé.
|
||||||
|
.B dhcp-remoteid
|
||||||
|
est supporté en IPv6 (mais non dhcp-circuitid).
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-subscrid=set:<label>,<identifiant d'abonné>
|
.B --dhcp-subscrid=set:<label>,<identifiant d'abonné>
|
||||||
Associe des options de relais DHCP issues de la RFC3993 à des labels.
|
(IPv4 et IPv6) Associe des options de relais DHCP issues de la RFC3993 à des
|
||||||
|
labels.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-proxy[=<adresse ip>]......
|
.B --dhcp-proxy[=<adresse ip>]......
|
||||||
Un agent relai DHCP normal est uniquement utilisé pour faire suivre les
|
(IPv4 seulement) Un agent relai DHCP normal est uniquement utilisé pour faire
|
||||||
éléments initiaux de l'interaction avec le serveur DHCP. Une fois que le
|
suivre les éléments initiaux de l'interaction avec le serveur DHCP. Une fois
|
||||||
client est configuré, il communique directement avec le serveur. Cela n'est pas
|
que le client est configuré, il communique directement avec le serveur. Cela
|
||||||
souhaitable si le relais rajoute des informations supplémentaires aux paquets
|
n'est pas souhaitable si le relais rajoute des informations supplémentaires
|
||||||
DHCP, telles que celles utilisées dans
|
aux paquets DHCP, telles que celles utilisées dans
|
||||||
.B dhcp-circuitid
|
.B dhcp-circuitid
|
||||||
et
|
et
|
||||||
.B dhcp-remoteid.
|
.B dhcp-remoteid.
|
||||||
@@ -973,26 +1093,28 @@ configuration dhcp-host de Dnsmasq, ainsi que le contenu des fichiers /etc/hosts
|
|||||||
et /etc/ethers.
|
et /etc/ethers.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-generate-names=tag:<label>[,tag:<label>]
|
.B --dhcp-generate-names=tag:<label>[,tag:<label>]
|
||||||
Générer un nom pour les clients DHCP qui autrement n'en aurait pas, en
|
(IPv4 seulement) Générer un nom pour les clients DHCP qui autrement n'en aurait
|
||||||
utilisant l'adresse MAC sous sa forme hexadécimale, séparée par des tirets.
|
pas, en utilisant l'adresse MAC sous sa forme hexadécimale, séparée par des
|
||||||
|
tirets.
|
||||||
Noter que si un hôte fourni un nom, celui-ci sera utilisé de préférence au nom
|
Noter que si un hôte fourni un nom, celui-ci sera utilisé de préférence au nom
|
||||||
autogénéré, à moins que
|
autogénéré, à moins que
|
||||||
.B --dhcp-ignore-names
|
.B --dhcp-ignore-names
|
||||||
ne soit positionné.
|
ne soit positionné.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-broadcast=[tag:<label>[,tag:<label>]]
|
.B --dhcp-broadcast=[tag:<label>[,tag:<label>]]
|
||||||
Lorsque tous les labels fournis dans l'option sont présents, toujours utiliser
|
(IPv4 seulement) Lorsque tous les labels fournis dans l'option sont présents,
|
||||||
le broadcast pour communiquer avec l'hôte lorsque celui-ci n'est
|
toujours utiliser le broadcast pour communiquer avec l'hôte lorsque celui-ci
|
||||||
pas configuré. Il est possible de ne spécifier aucun label, auquel cas cette
|
n'est pas configuré. Il est possible de ne spécifier aucun label, auquel cas
|
||||||
option s'applique inconditionnellement. La plupart des clients DHCP nécessitant une réponse par le biais
|
cette option s'applique inconditionnellement. La plupart des clients DHCP
|
||||||
d'un broadcast activent une option dans leur requête, ce qui fait que cela
|
nécessitant une réponse par le biais d'un broadcast activent une option dans
|
||||||
se fait automatiquement, mais ce n'est pas la cas de certains vieux clients BOOTP.
|
leur requête, ce qui fait que cela se fait automatiquement, mais ce n'est pas
|
||||||
|
le cas de certains vieux clients BOOTP.
|
||||||
.TP
|
.TP
|
||||||
.B \-M, --dhcp-boot=[tag:<label>,]<nom de fichier>,[<nom de serveur>[,<adresse de serveur>|<nom du serveur tftp>]]
|
.B \-M, --dhcp-boot=[tag:<label>,]<nom de fichier>,[<nom de serveur>[,<adresse de serveur>|<nom du serveur tftp>]]
|
||||||
Spécifie les options BOOTP devant être retournées par le serveur DHCP. Le nom de
|
(IPv4 seulement) Spécifie les options BOOTP devant être retournées par le
|
||||||
serveur ainsi que l'adresse sont optionnels : s'ils ne sont pas fournis, le nom
|
serveur DHCP. Le nom de serveur ainsi que l'adresse sont optionnels : s'ils
|
||||||
est laissé vide et l'adresse fournie est celle de la machine sur laquelle
|
ne sont pas fournis, le nom est laissé vide et l'adresse fournie est celle de
|
||||||
s'exécute Dnsmasq. Si Dnsmasq founit un service TFTP (voir
|
la machine sur laquelle s'exécute Dnsmasq. Si Dnsmasq founit un service TFTP (voir
|
||||||
.B --enable-tftp
|
.B --enable-tftp
|
||||||
), alors seul un nom de fichier est requis ici pour permettre un démarrage par
|
), alors seul un nom de fichier est requis ici pour permettre un démarrage par
|
||||||
le réseau.
|
le réseau.
|
||||||
@@ -1018,7 +1140,7 @@ Veuillez noter que dans ce mode séquentiel, les clients qui laissent expirer
|
|||||||
leur bail ont beaucoup plus de chance de voir leur adresse IP changer, aussi
|
leur bail ont beaucoup plus de chance de voir leur adresse IP changer, aussi
|
||||||
cette option ne devrait pas être utilisée dans un cas général.
|
cette option ne devrait pas être utilisée dans un cas général.
|
||||||
.TP
|
.TP
|
||||||
.B --pxe-service=[tag:<label>,]<CSA>,<entrée de menu>[,<nom de fichier>|<type de service de démarrage>][,<adresse de serveur>]
|
.B --pxe-service=[tag:<label>,]<CSA>,<entrée de menu>[,<nom de fichier>|<type de service de démarrage>][,<adresse de serveur>|<nom de serveur>]
|
||||||
La plupart des ROMS de démarrage PXE ne permettent au système PXE que la simple
|
La plupart des ROMS de démarrage PXE ne permettent au système PXE que la simple
|
||||||
obtention d'une adresse IP, le téléchargement du fichier spécifié dans
|
obtention d'une adresse IP, le téléchargement du fichier spécifié dans
|
||||||
.B dhcp-boot
|
.B dhcp-boot
|
||||||
@@ -1036,17 +1158,20 @@ client PXE qu'il faut télécharger ce fichier via TFTP, soit depuis ce serveur
|
|||||||
(l'option
|
(l'option
|
||||||
.B enable-tftp
|
.B enable-tftp
|
||||||
doit être spécifiée pour que cela marche), soit depuis un autre serveur TFTP
|
doit être spécifiée pour que cela marche), soit depuis un autre serveur TFTP
|
||||||
si une adresse de serveur est fournie.
|
si une adresse ou un nom de serveur est fournie.
|
||||||
Veuillez noter que le suffixe de "couche" (en principe ".0") est fourni par PXE
|
Veuillez noter que le suffixe de "couche" (en principe ".0") est fourni par PXE
|
||||||
et ne doit pas être rajouté au nom de fichier. Si une valeur numérique entière
|
et ne doit pas être rajouté au nom de fichier. Si une valeur numérique entière
|
||||||
est fournir pour le type de démarrage, en remplacement du nom de fichier, le
|
est fournir pour le type de démarrage, en remplacement du nom de fichier, le
|
||||||
client PXE devra chercher un service de démarrage de ce type sur le réseau.
|
client PXE devra chercher un service de démarrage de ce type sur le réseau.
|
||||||
Cette recherche peut être faite via broadcast ou directement auprès d'un
|
Cette recherche peut être faite via broadcast ou directement auprès d'un
|
||||||
serveur si son adresse IP est fournie dans l'option.
|
serveur si son adresse IP ou son nom sont fournis dans l'option.
|
||||||
Si aucun nom de fichier n'est donné ni aucune valeur de type de service de
|
Si aucun nom de fichier n'est donné ni aucune valeur de type de service de
|
||||||
démarrage n'est fournie (ou qu'une valeur de 0 est donnée pour le type de
|
démarrage n'est fournie (ou qu'une valeur de 0 est donnée pour le type de
|
||||||
service), alors l'entrée de menu provoque l'interruption du démarrage par
|
service), alors l'entrée de menu provoque l'interruption du démarrage par
|
||||||
le réseau et la poursuite du démarrage sur un média local.
|
le réseau et la poursuite du démarrage sur un média local. L'adresse de serveur
|
||||||
|
peut être donnée sous la forme de nom de domaine qui est recherché dans
|
||||||
|
/etc/hosts. Ce nom peut-être associé à plusieurs adresses IP, qui dans ce cas
|
||||||
|
sont utilisées à tour de rôle (en "round-robin").
|
||||||
.TP
|
.TP
|
||||||
.B --pxe-prompt=[tag:<label>,]<invite>[,<délai>]
|
.B --pxe-prompt=[tag:<label>,]<invite>[,<délai>]
|
||||||
Cette option permet d'afficher une invite à la suite du démarrage PXE. Si un
|
Cette option permet d'afficher une invite à la suite du démarrage PXE. Si un
|
||||||
@@ -1079,38 +1204,39 @@ créant des milliers de baux et utilisant beaucoup de mémoire dans le processus
|
|||||||
Dnsmasq.
|
Dnsmasq.
|
||||||
.TP
|
.TP
|
||||||
.B \-K, --dhcp-authoritative
|
.B \-K, --dhcp-authoritative
|
||||||
Cette option doit être donnée lorsque Dnsmasq est le seul serveur DHCP sur le
|
(IPv4 seulement) Cette option doit être donnée lorsque Dnsmasq est le seul
|
||||||
réseau. Cela change le comportement par défaut qui est celui d'un strict respect
|
serveur DHCP sur le réseau. Cela change le comportement par défaut qui est
|
||||||
des RFC, afin que les requêtes DHCP pour des baux inconnus par des hôtes
|
celui d'un strict respect des RFC, afin que les requêtes DHCP pour des baux
|
||||||
inconnus ne soient pas ignorées. Cela permet à de nouveaux hôtes d'obtenir des
|
inconnus par des hôtes inconnus ne soient pas ignorées. Cela permet à de
|
||||||
baux sans tenir compte de fastidieuses temporisations ("timeout"). Cela permet
|
nouveaux hôtes d'obtenir des baux sans tenir compte de fastidieuses
|
||||||
également à Dnsmasq de reconstruire sa base de donnée contenant les baux sans
|
temporisations ("timeout"). Cela permet également à Dnsmasq de reconstruire
|
||||||
que les clients n'aient besoin de redemander un bail, si celle-ci est perdue.
|
sa base de données contenant les baux sans que les clients n'aient besoin de
|
||||||
|
redemander un bail, si celle-ci est perdue.
|
||||||
.TP
|
.TP
|
||||||
.B --dhcp-alternate-port[=<port serveur>[,<port client>]]
|
.B --dhcp-alternate-port[=<port serveur>[,<port client>]]
|
||||||
Change les ports utilisés par défaut pour le DHCP. Si cette option est donnée
|
(IPv4 seulement) Change les ports utilisés par défaut pour le DHCP. Si cette
|
||||||
toute seule sans arguments, alors change les ports utilisés pour le DHCP
|
option est donnée seule sans argument, alors change les ports utilisés pour le
|
||||||
de 67 et 68 respectivement à 1067 et 1068. Si un seul argument est donné, ce
|
DHCP de 67 et 68 respectivement à 1067 et 1068. Si un seul argument est donné, ce
|
||||||
numéro est utilisé pour le port serveur et ce numéro plus 1 est utilisé pour le
|
numéro est utilisé pour le port serveur et ce numéro plus 1 est utilisé pour le
|
||||||
port client. Enfin, en fournissant deux numéros de ports, il est possible de
|
port client. Enfin, en fournissant deux numéros de ports, il est possible de
|
||||||
spécifier arbitrairement 2 ports à la fois pour le serveur et pour le client DHCP.
|
spécifier arbitrairement 2 ports à la fois pour le serveur et pour le client DHCP.
|
||||||
.TP
|
.TP
|
||||||
.B \-3, --bootp-dynamic[=<identifiant de réseau>[,<identifiant de réseau>]]
|
.B \-3, --bootp-dynamic[=<identifiant de réseau>[,<identifiant de réseau>]]
|
||||||
Permet l'allocation dynamique d'adresses IP à des clients BOOTP. Utiliser cette
|
(IPv4 seulement) Permet l'allocation dynamique d'adresses IP à des clients BOOTP.
|
||||||
option avec précaution, une adresse allouée à un client BOOTP étant perpétuelle,
|
Utiliser cette option avec précaution, une adresse allouée à un client BOOTP
|
||||||
et de fait n'est plus disponibles pour d'autres hôtes. Si aucun argument n'est
|
étant perpétuelle, et de fait n'est plus disponibles pour d'autres hôtes. Si
|
||||||
donné, alors cette option permet une allocation dynamique dans tous les cas. Si
|
aucun argument n'est donné, alors cette option permet une allocation dynamique
|
||||||
des arguments sont spécifiés, alors l'allocation ne se fait que lorsque tous
|
dans tous les cas. Si des arguments sont spécifiés, alors l'allocation ne se
|
||||||
les identifiants coïncident. Il est possible de répeter cette option avec
|
fait que lorsque tous les identifiants coïncident. Il est possible de répeter
|
||||||
plusieurs jeux d'arguments.
|
cette option avec plusieurs jeux d'arguments.
|
||||||
.TP
|
.TP
|
||||||
.B \-5, --no-ping
|
.B \-5, --no-ping
|
||||||
Par défaut, le serveur DHCP tente de s'assurer qu'une adresse n'est pas utilisée
|
(IPv4 seulement) Par défaut, le serveur DHCP tente de s'assurer qu'une adresse
|
||||||
avant de l'allouer à un hôte. Cela est fait en envoyant une requête ICMP de type
|
n'est pas utilisée avant de l'allouer à un hôte. Cela est fait en envoyant une
|
||||||
"echo request" (aussi connue sous le nom de "ping") à l'adresse en question. Si
|
requête ICMP de type "echo request" (aussi connue sous le nom de "ping") à
|
||||||
le serveur obtient une réponse, alors l'adresse doit déjà être utilisée et une
|
l'adresse en question. Si le serveur obtient une réponse, alors l'adresse doit
|
||||||
autre est essayée. Cette option permet de supprimer cette vérification. A
|
déjà être utilisée et une autre est essayée. Cette option permet de supprimer
|
||||||
utiliser avec précaution.
|
cette vérification. A utiliser avec précaution.
|
||||||
.TP
|
.TP
|
||||||
.B --log-dhcp
|
.B --log-dhcp
|
||||||
Traces additionnelles pour le service DHCP : enregistre toutes les options
|
Traces additionnelles pour le service DHCP : enregistre toutes les options
|
||||||
@@ -1120,18 +1246,30 @@ détermination de celles-ci.
|
|||||||
.B \-l, --dhcp-leasefile=<chemin de fichier>
|
.B \-l, --dhcp-leasefile=<chemin de fichier>
|
||||||
Utilise le fichier dont le chemin est fourni pour stocker les informations de
|
Utilise le fichier dont le chemin est fourni pour stocker les informations de
|
||||||
baux DHCP.
|
baux DHCP.
|
||||||
.TP
|
.TP
|
||||||
|
.B --dhcp-duid=<ID d'entreprise>,<uid>
|
||||||
|
(IPv6 seulement) Spécifie le numéro d'UID de serveur persistant que le serveur
|
||||||
|
DHCPv6 doit utiliser. Cette option n'est normalement pas requise, Dnsmasq
|
||||||
|
créant un DUID automatiquement lorsque cela est nécessaire. Lorsque cette
|
||||||
|
option est positionnée, elle fournit à Dnsmasq les données nécessaires à la
|
||||||
|
création d'un DUID de type DUID-EN. Veuillez noter qu'une fois créé, le DUID
|
||||||
|
est stocké dans la base des baux, aussi changer entre un DUID créé
|
||||||
|
automatiquement et un DUID-EN et vice-versa impose de réinitialiser la base de
|
||||||
|
baux. Le numéro d'ID d'entreprise est assigné par l'IANA, et l'uid est une
|
||||||
|
chaine hexadécimale unique à chaque serveur.
|
||||||
|
.TP
|
||||||
.B \-6 --dhcp-script=<chemin de fichier>
|
.B \-6 --dhcp-script=<chemin de fichier>
|
||||||
Lorsqu'un bail DHCP est créé, ou qu'un ancien est supprimé, le fichier dont le
|
Lorsqu'un bail DHCP est créé, qu'un ancien est supprimé, ou qu'un transfert
|
||||||
|
TFTP est terminé, le fichier dont le
|
||||||
chemin est spécifié est exécuté. Le <chemin de fichier> doit être un chemin
|
chemin est spécifié est exécuté. Le <chemin de fichier> doit être un chemin
|
||||||
absolu, aucune recherche n'est effectuée via la variable d'environnement PATH.
|
absolu, aucune recherche n'est effectuée via la variable d'environnement PATH.
|
||||||
Les arguments fournis à celui-ci sont soit
|
Les arguments fournis à celui-ci sont soit
|
||||||
"add" ("ajouter"), "old" ("ancien") ou "del" ("supprimer"), suivi de l'adresse
|
"add" ("ajouter"), "old" ("ancien") ou "del" ("supprimer"), suivi de l'adresse
|
||||||
MAC de l'hôte puis l'adresse IP et le nom d'hôte si celui-ci est
|
MAC de l'hôte (ou le DUID pour IPv6) puis l'adresse IP et le nom d'hôte si
|
||||||
connu."add" signifie qu'un bail a été créé, "del" signifie qu'il a été supprimé,
|
celui-ci est connu."add" signifie qu'un bail a été créé, "del" signifie qu'il a
|
||||||
"old" notifie que le bail existait au lancement de Dnsmasq, ou un changement
|
été supprimé, "old" notifie que le bail existait au lancement de Dnsmasq, ou un
|
||||||
d'adresse MAC ou de nom d'hôte pour un bail existant (ou, dans le cas où
|
changement d'adresse MAC ou de nom d'hôte pour un bail existant (ou, dans le cas
|
||||||
leasefile-ro est spécifié, un changement de durée de bail ou d'identifiant
|
où leasefile-ro est spécifié, un changement de durée de bail ou d'identifiant
|
||||||
d'hôte). Si l'adresse Mac est d'un type de réseau autre qu'ethernet, il est
|
d'hôte). Si l'adresse Mac est d'un type de réseau autre qu'ethernet, il est
|
||||||
nécessaire de la préceder du type de réseau, par exemple "06-01:23:45:67:89:ab"
|
nécessaire de la préceder du type de réseau, par exemple "06-01:23:45:67:89:ab"
|
||||||
pour du token ring. Le processus est exécuté en temps que super-utilisateur
|
pour du token ring. Le processus est exécuté en temps que super-utilisateur
|
||||||
@@ -1141,18 +1279,16 @@ pour changer son UID pour celle d'un utilisateur non-privilégié.
|
|||||||
L'environnement est hérité de celui de l'invocation du processus Dnsmasq,
|
L'environnement est hérité de celui de l'invocation du processus Dnsmasq,
|
||||||
auquel se rajoute quelques unes ou toutes les variables décrites ci-dessous :
|
auquel se rajoute quelques unes ou toutes les variables décrites ci-dessous :
|
||||||
|
|
||||||
DNSMASQ_CLIENT_ID, si l'hôte a fourni un identifiant de client.
|
Pour IPv4 et IPv6 :
|
||||||
|
|
||||||
DNSMASQ_DOMAIN si le nom de domaine pleinement qualifié de l'hôte est connu, la
|
DNSMASQ_DOMAIN si le nom de domaine pleinement qualifié de l'hôte est connu, la
|
||||||
part relative au domaine y est stockée. (Notez que le nom d'hôte transmis comme
|
part relative au domaine y est stockée. (Notez que le nom d'hôte transmis comme
|
||||||
argument au script n'est jamais pleinement qualifié).
|
argument au script n'est jamais pleinement qualifié).
|
||||||
|
|
||||||
Si le client fournit une information de classe de vendeur, un nom d'hôte, ou
|
Si le client fournit un nom d'hôte, DNSMASQ_SUPPLIED_HOSTNAME.
|
||||||
des classes d'utilisateur, celles-ci sont fournies dans les
|
|
||||||
variables DNSMASQ_VENDOR_CLASS et DNSMASQ_USER_CLASS0 à DNSMASQ_USER_CLASSn
|
Si le client fournit des classes d'utilisateur, DNSMASQ_USER_CLASS0 à
|
||||||
et DNSMASQ_SUPPLIED_HOSTNAME respectivement, mais seulement pour les actions
|
DNSMASQ_USER_CLASSn.
|
||||||
"add" et "old" lorsqu'un hôte reprend un bail existant, ces variables n'étant
|
|
||||||
pas stockées dans la base de baux de Dnsmasq.
|
|
||||||
|
|
||||||
Si Dnsmasq a été compilé avec l'option HAVE_BROKEN_RTC ("horloge RTC
|
Si Dnsmasq a été compilé avec l'option HAVE_BROKEN_RTC ("horloge RTC
|
||||||
défectueuse"), alors la durée du bail (en secondes) est stockée dans la
|
défectueuse"), alors la durée du bail (en secondes) est stockée dans la
|
||||||
@@ -1175,6 +1311,33 @@ relai DHCP pour contacter Dnsmasq, si l'adresse IP du relai est connue.
|
|||||||
DNSMASQ_TAGS contient tous les labels fournis pendant la transaction DHCP,
|
DNSMASQ_TAGS contient tous les labels fournis pendant la transaction DHCP,
|
||||||
séparés par des espaces.
|
séparés par des espaces.
|
||||||
|
|
||||||
|
DNSMASQ_LOG_DHCP est positionné si
|
||||||
|
.B --log-dhcp
|
||||||
|
est activé.
|
||||||
|
|
||||||
|
Pour IPv4 seulement :
|
||||||
|
|
||||||
|
DNSMASQ_CLIENT_ID, si l'hôte a fourni un identifiant de client.
|
||||||
|
|
||||||
|
Si le client fournit une information de classe de vendeur, DNSMASQ_VENDOR_CLASS.
|
||||||
|
|
||||||
|
Pour IPv6 seulement :
|
||||||
|
|
||||||
|
Si le client fournit une classe de vendeur (vendor-class), positionne
|
||||||
|
DNSMASQ_VENDOR_CLASS_ID avec comme contenu le numéro IANA de l'entreprise pour
|
||||||
|
la classe, et DNSMASQ_VENDOR_CLASS0..DNSMASQ_VENDOR_CLASSn pour les données.
|
||||||
|
|
||||||
|
DNSMASQ_SERVER_DUID contient le DUID du serveur : cette valeur est la même
|
||||||
|
pour chaque appel au script.
|
||||||
|
|
||||||
|
DNSMASQ_IAID contenant l'IAID pour le bail. Si le bail est une allocation
|
||||||
|
temporaire, cela est préfixé par le caractère 'T'.
|
||||||
|
|
||||||
|
A noter que le nom d'hôte fourni, la classe de vendeur ou les données de classe
|
||||||
|
d'utilisateur sont uniquement fournies pour les actions "add" ou l'action "old"
|
||||||
|
lorsqu'un hôte reprend un bail existant, puisque ces informations ne sont pas
|
||||||
|
conservées dans la base de baux de dnsmasq.
|
||||||
|
|
||||||
Tous les descripteurs de fichiers sont fermés, sauf stdin, stdout et stderr qui
|
Tous les descripteurs de fichiers sont fermés, sauf stdin, stdout et stderr qui
|
||||||
sont ouverts sur /dev/null (sauf en mode déverminage).
|
sont ouverts sur /dev/null (sauf en mode déverminage).
|
||||||
|
|
||||||
@@ -1191,11 +1354,72 @@ Au démarrage de Dnsmasq, le script sera invoqué pour chacun des baux existants
|
|||||||
dans le fichier des baux. Le script sera lancé avec l'action "del" pour les
|
dans le fichier des baux. Le script sera lancé avec l'action "del" pour les
|
||||||
baux expirés, et "old" pour les autres. Lorsque Dnsmasq reçoit un signal HUP,
|
baux expirés, et "old" pour les autres. Lorsque Dnsmasq reçoit un signal HUP,
|
||||||
le script sera invoqué avec une action "old" pour tous les baux existants.
|
le script sera invoqué avec une action "old" pour tous les baux existants.
|
||||||
.TP
|
|
||||||
|
Il existe deux autres actions pouvant apparaître comme argument au script :
|
||||||
|
"init" et "tftp". D'autres sont susceptibles d'être rajoutées dans le futur,
|
||||||
|
aussi les scripts devraient-être écrits de sorte à ignorer les actions
|
||||||
|
inconnues. "init" est décrite ci-dessous dans
|
||||||
|
.B --leasefile-ro.
|
||||||
|
L'action "tftp" est invoquée lorsqu'un transfert de fichier TFTP s'est
|
||||||
|
terminé. Ses arguments sont la taille du fichier en octets, l'adresse à
|
||||||
|
laquelle le fichier a été envoyé, ainsi que le chemin complet du fichier.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B --dhcp-luascript=<chemin>
|
||||||
|
Spécifie un script écrit en Lua, devant être exécuté lorsque des baux sont
|
||||||
|
créés, détruits ou modifiés. Pour utiliser cette option, dnsmasq doit être
|
||||||
|
compilé avec avec le support de Lua. L'interpréteur Lua est initialisé une
|
||||||
|
seule fois, lorsque dnsmasq démarre, ce qui fait que les variables globales
|
||||||
|
persistent entre les évênements liés aux baux. Le code Lua doit définir une
|
||||||
|
fonction
|
||||||
|
.B lease
|
||||||
|
et peut fournir des fonctions
|
||||||
|
.B init
|
||||||
|
et
|
||||||
|
.B shutdown
|
||||||
|
qui sont appellées, sans arguments, lorsque dnsmasq démarre ou s'arrête.
|
||||||
|
Il peut également fournir une fonction
|
||||||
|
.B tftp.
|
||||||
|
|
||||||
|
La fonction
|
||||||
|
.B lease
|
||||||
|
reçoit les informations détaillées dans
|
||||||
|
.B --dhcp-script.
|
||||||
|
Il reçoit deux arguments. Le premier spécifie l'action, qui est une chaîne de
|
||||||
|
caractères contenant les valeurs "add" (ajout), "old" (réactivation d'un bail
|
||||||
|
existant) ou "del" (suppression). Le deuxième est une table contenant des
|
||||||
|
paires de valeurs de labels. Les labels correspondent pour l'essentiel aux
|
||||||
|
valeurs d'environnement détaillées ci-dessus, ainsi le label "domain" (domaine)
|
||||||
|
contient les mêmes données que la variable d'environnement DNSMASQ_DOMAIN. Il
|
||||||
|
existe quelques labels supplémentaires contenant les données fournies comme
|
||||||
|
arguments à
|
||||||
|
.B --dhcp-script.
|
||||||
|
Ces labels sont
|
||||||
|
.B mac_address, ip_address
|
||||||
|
(pour respectivement l'adresse MAC et l'adresse IP)
|
||||||
|
et
|
||||||
|
.B hostname
|
||||||
|
(le nom d'hôte) dans le cas d'IPv4, et
|
||||||
|
.B client_duid, ip_address
|
||||||
|
(valeur DUID du client et adresse IP respectivement)
|
||||||
|
ainsi que
|
||||||
|
.B hostname
|
||||||
|
(le nom d'hôte) dans le cas d'IPv6.
|
||||||
|
|
||||||
|
La fonction
|
||||||
|
.B tftp
|
||||||
|
est appelée de la même façon que la fonction "lease", et la table contient les
|
||||||
|
labels
|
||||||
|
.B destination_address,
|
||||||
|
.B file_name
|
||||||
|
et
|
||||||
|
.B file_size
|
||||||
|
(respectivement "adresse de destination", "nom de fichier" et "taille de fichier").
|
||||||
|
.TP
|
||||||
.B --dhcp-scriptuser
|
.B --dhcp-scriptuser
|
||||||
Spécifie l'utilisateur sous lequel le script lease-change doit être exécuté. La
|
Spécifie l'utilisateur sous lequel le script shell lease-change ou le script
|
||||||
valeur par défaut correspond à l'utilisateur root mais peut-être changée par le
|
doivent être exécutés. La valeur par défaut correspond à l'utilisateur root
|
||||||
biais de cette option.
|
mais peut-être changée par le biais de cette option.
|
||||||
.TP
|
.TP
|
||||||
.B \-9, --leasefile-ro
|
.B \-9, --leasefile-ro
|
||||||
Supprimer complètement l'usage du fichier servant de base de donnée pour les
|
Supprimer complètement l'usage du fichier servant de base de donnée pour les
|
||||||
@@ -1257,7 +1481,7 @@ Si la gamme d'adresse est fournie sous la forme
|
|||||||
qui a pour effect d'ajouter --local-declarations aux requêtes DNS directes et
|
qui a pour effect d'ajouter --local-declarations aux requêtes DNS directes et
|
||||||
inverses. C-à-d
|
inverses. C-à-d
|
||||||
.B --domain=thekelleys.org.uk,192.168.0.0/24,local
|
.B --domain=thekelleys.org.uk,192.168.0.0/24,local
|
||||||
est indentique à
|
est identique à
|
||||||
.B --domain=thekelleys.org.uk,192.168.0.0/24
|
.B --domain=thekelleys.org.uk,192.168.0.0/24
|
||||||
--local=/thekelleys.org.uk/ --local=/0.168.192.in-addr.arpa/
|
--local=/thekelleys.org.uk/ --local=/0.168.192.in-addr.arpa/
|
||||||
La taille de réseau doit-être de 8, 16 ou 24 pour être valide.
|
La taille de réseau doit-être de 8, 16 ou 24 pour être valide.
|
||||||
@@ -1280,12 +1504,42 @@ sans gamme d'adresses de spécifié lorsque l'option
|
|||||||
.B --dhcp-fqdn
|
.B --dhcp-fqdn
|
||||||
est configurée.
|
est configurée.
|
||||||
.TP
|
.TP
|
||||||
.B --enable-tftp[=<interface>]
|
.B --dhcp-client-update
|
||||||
|
Normalement, lorsque dnsmasq fournit un bail DHCP, il positionne un label
|
||||||
|
dans l'option FQDN pour indiquer au client qu'il ne doit pas tenter de faire
|
||||||
|
une mise à jour DDNS avec son nom et son adresse IP. Ceci parce que la paire
|
||||||
|
Nom-IP est rajoutée automatiquement dans la partie DNS de dnsmasq. Cette option
|
||||||
|
inhibe ce comportement ce qui est utile, par exemple, pour permettre aux clients
|
||||||
|
Windows de la mise à jour de serveurs Active Directory. Voir la RFC 4702 pour
|
||||||
|
plus de détails.
|
||||||
|
.TP
|
||||||
|
.B --enable-ra
|
||||||
|
Active la fonctionalité d'annonces routeurs IPv6 ("IPv6 Router Advertisement").
|
||||||
|
DHCPv6 ne gère pas la configuration complète du réseau de la même façon que
|
||||||
|
DHCPv4. La découverte de routeurs et la découverte (éventuelle) de préfixes pour
|
||||||
|
la création autonome d'adresse sont gérées par un protocole différent.
|
||||||
|
Lorsque DHCP est utilisé, seul un sous-ensemble de tout ceci est nécessaire et
|
||||||
|
dnsmasq est à même de le gérer, en utilisant la configuration DHCP présente pour
|
||||||
|
fournir la majorité des données. Lorsque les annonces routeurs (RA pour "Router
|
||||||
|
Advertisement") sont activées, dnsmasq va annoncer un préfixe pour chaque
|
||||||
|
dhcp-range et, par défaut, fournir comme valeur de routeur et de DNS récursif
|
||||||
|
la valeur d'adresse link-local appropriée parmi celles de la machine sur
|
||||||
|
laquelle tourne dnsmasq.
|
||||||
|
Par défaut, les bits "managed address" sont positionnés, et le bit "use SLAAC"
|
||||||
|
("utiliser SLAAC") est réinitialisé. Cela peut-être changé pour des
|
||||||
|
sous-réseaux donnés par le biais du mot clef de mode décris dans
|
||||||
|
.B --dhcp-range.
|
||||||
|
Les paramètres DNS du RFC6106 sont inclus dans les annonces. Par défaut,
|
||||||
|
l'adresse link-local appropriée parmi celles de la machine sur laquelle tourne
|
||||||
|
dnsmasq est spécifiée comme DNS récursif. Si elles sont fournies, les
|
||||||
|
options dns-server et domain-search sont utilisées respectivement pour RDNSS et
|
||||||
|
DNSSL.
|
||||||
|
.TP
|
||||||
|
.B --enable-tftp
|
||||||
Active la fonction serveur TFTP. Celui-ci est de manière délibérée limité aux
|
Active la fonction serveur TFTP. Celui-ci est de manière délibérée limité aux
|
||||||
fonctions nécessaires au démarrage par le réseau ("net-boot") d'un client. Seul
|
fonctions nécessaires au démarrage par le réseau ("net-boot") d'un client. Seul
|
||||||
un accès en lecture est possible; les extensions tsize et blksize sont supportées
|
un accès en lecture est possible; les extensions tsize et blksize sont supportées
|
||||||
(tsize est seulement supporté en mode octet). Voir dans la section NOTES les
|
(tsize est seulement supporté en mode octet).
|
||||||
informations relatives à la spécification de l'interface.
|
|
||||||
.TP
|
.TP
|
||||||
.B --tftp-root=<répertoire>[,<interface>]
|
.B --tftp-root=<répertoire>[,<interface>]
|
||||||
Les fichiers à fournir dans les transferts TFTP seront cherchés en prenant le
|
Les fichiers à fournir dans les transferts TFTP seront cherchés en prenant le
|
||||||
@@ -1323,6 +1577,13 @@ Sans cela, en effet, l'accès de tous les fichiers du serveur pour lequel le
|
|||||||
droit de lecture pour tout le monde est positionné ("world-readable") devient
|
droit de lecture pour tout le monde est positionné ("world-readable") devient
|
||||||
possible par n'importe quel hôte sur le réseau.
|
possible par n'importe quel hôte sur le réseau.
|
||||||
.TP
|
.TP
|
||||||
|
.B --tftp-lowercase
|
||||||
|
Converti les noms de fichiers des requêtes TFTP en minuscules. Cela est utile
|
||||||
|
pour les requêtes effectuées depuis les machines Windows, dont les systèmes
|
||||||
|
de fichiers sont insensibles à la casse et pour lesquels la détermination
|
||||||
|
de la casse est parfois un peu aléatoire. A noter que le serveur tftp de
|
||||||
|
dnsmasq converti systématiquement les "\\" en "/" dans les noms de fichiers.
|
||||||
|
.TP
|
||||||
.B --tftp-max=<connexions>
|
.B --tftp-max=<connexions>
|
||||||
Définit le nombre maximum de connexions TFTP simultanées autorisées. La valeur
|
Définit le nombre maximum de connexions TFTP simultanées autorisées. La valeur
|
||||||
par défaut est de 50. Lorsqu'un grand nombre de connexions TFTP est spécifié,
|
par défaut est de 50. Lorsqu'un grand nombre de connexions TFTP est spécifié,
|
||||||
@@ -1547,10 +1808,6 @@ ligne de commande au lieu d'un fichier de configuration, ne pas oublier
|
|||||||
d'échapper le caractère !, qui est un méta-caractère d'interpréteur de commande
|
d'échapper le caractère !, qui est un méta-caractère d'interpréteur de commande
|
||||||
shell).
|
shell).
|
||||||
|
|
||||||
+When selecting dhcp-options, a tag from dhcp-range is second class
|
|
||||||
+relative to other tags, to make it easy to override options for
|
|
||||||
+individual hosts, so
|
|
||||||
|
|
||||||
Lors de la sélection d'une option, une étiquette spécifiée par dhcp-range
|
Lors de la sélection d'une option, une étiquette spécifiée par dhcp-range
|
||||||
passe après les autres étiquettes, ce qui permet de facilement remplacer des
|
passe après les autres étiquettes, ce qui permet de facilement remplacer des
|
||||||
option génériques pour des hôtes spécifiques, ainsi :
|
option génériques pour des hôtes spécifiques, ainsi :
|
||||||
@@ -1590,51 +1847,6 @@ supprime la nécessité des associations statiques). Le paramètre
|
|||||||
que le label "bootp", permettant un certain contrôle sur les options retournées
|
que le label "bootp", permettant un certain contrôle sur les options retournées
|
||||||
aux différentes classes d'hôtes.
|
aux différentes classes d'hôtes.
|
||||||
|
|
||||||
Il est possible de spécifier un nom d'interface à
|
|
||||||
.B dhcp-range
|
|
||||||
sous la forme "interface:<nom d'interface>". La sémantique est comme suit :
|
|
||||||
Pour le DHCP, s'il existe une autre valeur de dhcp-range pour laquelle
|
|
||||||
_aucun_ nom d'interface n'est donné, alors le nom d'interface est ignoré
|
|
||||||
et dnsmasq se comporte comme si la partie spécifiant l'interface n'existait
|
|
||||||
pas, sinon le service DHCP n'est fourni qu'aux interfaces mentionnées dans
|
|
||||||
les déclarations dhcp-range. Pour le DNS, si il n'y a pas d'option
|
|
||||||
.B --interface
|
|
||||||
ou
|
|
||||||
.B --listen-address
|
|
||||||
, alors le comportement n'est pas impacté par la spécification d'interface. Si
|
|
||||||
l'une ou l'autre de ces options est présente, alors les interfaces mentionnées
|
|
||||||
dans les plages d'adresses dhcp-range sont rajoutées à la liste de celles
|
|
||||||
où le service DNS est assuré.
|
|
||||||
|
|
||||||
De manière similaire,
|
|
||||||
.B enable-tftp
|
|
||||||
peut prendre un nom d'interface, ce qui active le TFTP pour cette seule
|
|
||||||
interface, en ignorant les options
|
|
||||||
.B --interface
|
|
||||||
ou
|
|
||||||
.B --listen-address
|
|
||||||
De plus,
|
|
||||||
.B --tftp-secure
|
|
||||||
,
|
|
||||||
.B --tftp-unique-root
|
|
||||||
et
|
|
||||||
.B --tftp-no-blocksize
|
|
||||||
sont ignorées pour les requêtes sur de telles interfaces. (une directive
|
|
||||||
.B --tftp-root
|
|
||||||
donnant le chemin de la racine et une interface doit-être fournie).
|
|
||||||
|
|
||||||
Ces règles peuvent paraître étrange à première vue, mais elles permettent
|
|
||||||
d'ajouter à la configuration de dnsmasq des lignes de configuration de la
|
|
||||||
forme "dhcp-range=interface:virt0,192.168.0.4,192.168.0.200" afin de fournir
|
|
||||||
un service DHCP et DNS sur cette interface, sans pour autant affecter les
|
|
||||||
services fournis sur d'autres interfaces, malgré l'absence de paramètres
|
|
||||||
"interface=<interface>" sur les autres lignes de configuration.
|
|
||||||
"enable-tftp=virt0" et "tftp-root=<root>,virt0" effectuent la même chose pour
|
|
||||||
TFTP.
|
|
||||||
L'idée de tout cela est de permettre l'addition de telles lignes
|
|
||||||
automatiquement par libvirt ou un système équivalent, sans perturbation
|
|
||||||
d'une configuration manuelle existant par ailleurs.
|
|
||||||
|
|
||||||
.SH CODES DE SORTIE
|
.SH CODES DE SORTIE
|
||||||
.PP
|
.PP
|
||||||
0 - Dnsmasq s'est correctement lancé en tâche de fond, ou alors s'est
|
0 - Dnsmasq s'est correctement lancé en tâche de fond, ou alors s'est
|
||||||
|
|||||||
+537
-478
File diff suppressed because it is too large.
Load diff
+742
@@ -0,0 +1,742 @@
|
|||||||
|
/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 dated June, 1991, or
|
||||||
|
(at your option) version 3 dated 29 June, 2007.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_AUTH
|
||||||
|
|
||||||
|
static struct subnet *filter_zone(struct auth_zone *zone, int flag, struct all_addr *addr_u)
|
||||||
|
{
|
||||||
|
struct subnet *subnet;
|
||||||
|
|
||||||
|
for (subnet = zone->subnet; subnet; subnet = subnet->next)
|
||||||
|
{
|
||||||
|
if (subnet->is6 && (flag & F_IPV4))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!subnet->is6)
|
||||||
|
{
|
||||||
|
struct in_addr addr = addr_u->addr.addr4;
|
||||||
|
struct in_addr mask;
|
||||||
|
|
||||||
|
mask.s_addr = htonl(~((1 << (32 - subnet->prefixlen)) - 1));
|
||||||
|
|
||||||
|
if (is_same_net(addr, subnet->addr4, mask))
|
||||||
|
return subnet;
|
||||||
|
}
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else if (is_same_net6(&(addr_u->addr.addr6), &subnet->addr6, subnet->prefixlen))
|
||||||
|
return subnet;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int in_zone(struct auth_zone *zone, char *name, char **cut)
|
||||||
|
{
|
||||||
|
size_t namelen = strlen(name);
|
||||||
|
size_t domainlen = strlen(zone->domain);
|
||||||
|
|
||||||
|
if (cut)
|
||||||
|
*cut = NULL;
|
||||||
|
|
||||||
|
if (namelen >= domainlen &&
|
||||||
|
hostname_isequal(zone->domain, &name[namelen - domainlen]))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (namelen == domainlen)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (name[namelen - domainlen - 1] == '.')
|
||||||
|
{
|
||||||
|
if (cut)
|
||||||
|
*cut = &name[namelen - domainlen - 1];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, time_t now, union mysockaddr *peer_addr)
|
||||||
|
{
|
||||||
|
char *name = daemon->namebuff;
|
||||||
|
unsigned char *p, *ansp;
|
||||||
|
int qtype, qclass;
|
||||||
|
int nameoffset, axfroffset = 0;
|
||||||
|
int q, anscount = 0, authcount = 0;
|
||||||
|
struct crec *crecp;
|
||||||
|
int auth = 1, trunc = 0, nxdomain = 1, soa = 0, ns = 0, axfr = 0;
|
||||||
|
struct auth_zone *zone = NULL;
|
||||||
|
struct subnet *subnet = NULL;
|
||||||
|
char *cut;
|
||||||
|
struct mx_srv_record *rec, *move, **up;
|
||||||
|
struct txt_record *txt;
|
||||||
|
struct interface_name *intr;
|
||||||
|
struct naptr *na;
|
||||||
|
struct all_addr addr;
|
||||||
|
struct cname *a;
|
||||||
|
|
||||||
|
if (ntohs(header->qdcount) == 0 || OPCODE(header) != QUERY )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* determine end of question section (we put answers there) */
|
||||||
|
if (!(ansp = skip_questions(header, qlen)))
|
||||||
|
return 0; /* bad packet */
|
||||||
|
|
||||||
|
/* now process each question, answers go in RRs after the question */
|
||||||
|
p = (unsigned char *)(header+1);
|
||||||
|
|
||||||
|
for (q = ntohs(header->qdcount); q != 0; q--)
|
||||||
|
{
|
||||||
|
unsigned short flag = 0;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
/* save pointer to name for copying into answers */
|
||||||
|
nameoffset = p - (unsigned char *)header;
|
||||||
|
|
||||||
|
/* now extract name as .-concatenated string into name */
|
||||||
|
if (!extract_name(header, qlen, &p, name, 1, 4))
|
||||||
|
return 0; /* bad packet */
|
||||||
|
|
||||||
|
GETSHORT(qtype, p);
|
||||||
|
GETSHORT(qclass, p);
|
||||||
|
|
||||||
|
if (qclass != C_IN)
|
||||||
|
{
|
||||||
|
auth = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qtype == T_PTR)
|
||||||
|
{
|
||||||
|
if (!(flag = in_arpa_name_2_addr(name, &addr)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (zone = daemon->auth_zones; zone; zone = zone->next)
|
||||||
|
if ((subnet = filter_zone(zone, flag, &addr)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!zone)
|
||||||
|
{
|
||||||
|
auth = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag == F_IPV4)
|
||||||
|
{
|
||||||
|
for (intr = daemon->int_names; intr; intr = intr->next)
|
||||||
|
{
|
||||||
|
if (addr.addr.addr4.s_addr == get_ifaddr(intr->intr).s_addr)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
while (intr->next && strcmp(intr->intr, intr->next->intr) == 0)
|
||||||
|
intr = intr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intr)
|
||||||
|
{
|
||||||
|
if (in_zone(zone, intr->name, NULL))
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_IPV4 | F_REVERSE | F_CONFIG, intr->name, &addr, NULL);
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL,
|
||||||
|
T_PTR, C_IN, "d", intr->name))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((crecp = cache_find_by_addr(NULL, &addr, now, flag)))
|
||||||
|
do {
|
||||||
|
strcpy(name, cache_get_name(crecp));
|
||||||
|
|
||||||
|
if (crecp->flags & F_DHCP && !option_bool(OPT_DHCP_FQDN))
|
||||||
|
{
|
||||||
|
char *p = strchr(name, '.');
|
||||||
|
if (p)
|
||||||
|
*p = 0; /* must be bare name */
|
||||||
|
|
||||||
|
/* add external domain */
|
||||||
|
strcat(name, ".");
|
||||||
|
strcat(name, zone->domain);
|
||||||
|
log_query(flag | F_DHCP | F_REVERSE, name, &addr, record_source(crecp->uid));
|
||||||
|
found = 1;
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL,
|
||||||
|
T_PTR, C_IN, "d", name))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
else if (crecp->flags & (F_DHCP | F_HOSTS) && in_zone(zone, name, NULL))
|
||||||
|
{
|
||||||
|
log_query(crecp->flags & ~F_FORWARD, name, &addr, record_source(crecp->uid));
|
||||||
|
found = 1;
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL,
|
||||||
|
T_PTR, C_IN, "d", name))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} while ((crecp = cache_find_by_addr(crecp, &addr, now, flag)));
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
log_query(flag | F_NEG | F_NXDOMAIN | F_REVERSE | F_AUTH, NULL, &addr, NULL);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
cname_restart:
|
||||||
|
for (zone = daemon->auth_zones; zone; zone = zone->next)
|
||||||
|
if (in_zone(zone, name, &cut))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!zone)
|
||||||
|
{
|
||||||
|
auth = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (rec = daemon->mxnames; rec; rec = rec->next)
|
||||||
|
if (!rec->issrv && hostname_isequal(name, rec->name))
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
|
||||||
|
if (qtype == T_MX)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<MX>");
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_MX, C_IN, "sd", rec->weight, rec->target))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (move = NULL, up = &daemon->mxnames, rec = daemon->mxnames; rec; rec = rec->next)
|
||||||
|
if (rec->issrv && hostname_isequal(name, rec->name))
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
|
||||||
|
if (qtype == T_SRV)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<SRV>");
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_SRV, C_IN, "sssd",
|
||||||
|
rec->priority, rec->weight, rec->srvport, rec->target))
|
||||||
|
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* unlink first SRV record found */
|
||||||
|
if (!move)
|
||||||
|
{
|
||||||
|
move = rec;
|
||||||
|
*up = rec->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
up = &rec->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
up = &rec->next;
|
||||||
|
|
||||||
|
/* put first SRV record back at the end. */
|
||||||
|
if (move)
|
||||||
|
{
|
||||||
|
*up = move;
|
||||||
|
move->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (txt = daemon->rr; txt; txt = txt->next)
|
||||||
|
if (hostname_isequal(name, txt->name))
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
if (txt->class == qtype)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<RR>");
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, txt->class, C_IN, "t", txt->len, txt->txt))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (txt = daemon->txt; txt; txt = txt->next)
|
||||||
|
if (txt->class == C_IN && hostname_isequal(name, txt->name))
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
if (qtype == T_TXT)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<TXT>");
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_TXT, C_IN, "t", txt->len, txt->txt))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (na = daemon->naptr; na; na = na->next)
|
||||||
|
if (hostname_isequal(name, na->name))
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
if (qtype == T_NAPTR)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<NAPTR>");
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_NAPTR, C_IN, "sszzzd",
|
||||||
|
na->order, na->pref, na->flags, na->services, na->regexp, na->replace))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (intr = daemon->int_names; intr; intr = intr->next)
|
||||||
|
if (hostname_isequal(name, intr->name))
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
if (qtype == T_A && (addr.addr.addr4 = get_ifaddr(intr->intr)).s_addr != (in_addr_t) -1)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
log_query(F_FORWARD | F_CONFIG | F_IPV4, name, &addr, NULL);
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, T_A, C_IN, "4", &addr))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (a = daemon->cnames; a; a = a->next)
|
||||||
|
if (hostname_isequal(name, a->alias) )
|
||||||
|
{
|
||||||
|
log_query(F_CONFIG | F_CNAME, name, NULL, NULL);
|
||||||
|
strcpy(name, a->target);
|
||||||
|
if (!strchr(name, '.'))
|
||||||
|
{
|
||||||
|
strcat(name, ".");
|
||||||
|
strcat(name, zone->domain);
|
||||||
|
}
|
||||||
|
found = 1;
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL,
|
||||||
|
T_CNAME, C_IN, "d", name))
|
||||||
|
anscount++;
|
||||||
|
|
||||||
|
goto cname_restart;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qtype == T_A)
|
||||||
|
flag = F_IPV4;
|
||||||
|
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (qtype == T_AAAA)
|
||||||
|
flag = F_IPV6;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!cut)
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
|
||||||
|
if (qtype == T_SOA)
|
||||||
|
{
|
||||||
|
soa = 1; /* inhibits auth section */
|
||||||
|
found = 1;
|
||||||
|
log_query(F_RRNAME | F_AUTH, zone->domain, NULL, "<SOA>");
|
||||||
|
}
|
||||||
|
else if (qtype == T_AXFR)
|
||||||
|
{
|
||||||
|
if (daemon->auth_peers)
|
||||||
|
{
|
||||||
|
struct iname *peers;
|
||||||
|
|
||||||
|
if (peer_addr->sa.sa_family == AF_INET)
|
||||||
|
peer_addr->in.sin_port = 0;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else
|
||||||
|
peer_addr->in6.sin6_port = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (peers = daemon->auth_peers; peers; peers = peers->next)
|
||||||
|
if (sockaddr_isequal(peer_addr, &peers->addr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!peers)
|
||||||
|
{
|
||||||
|
if (peer_addr->sa.sa_family == AF_INET)
|
||||||
|
inet_ntop(AF_INET, &peer_addr->in.sin_addr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else
|
||||||
|
inet_ntop(AF_INET6, &peer_addr->in6.sin6_addr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
my_syslog(LOG_WARNING, _("ignoring zone transfer request from %s"), daemon->addrbuff);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
soa = 1; /* inhibits auth section */
|
||||||
|
ns = 1; /* ensure we include NS records! */
|
||||||
|
axfr = 1;
|
||||||
|
found = 1;
|
||||||
|
axfroffset = nameoffset;
|
||||||
|
log_query(F_RRNAME | F_AUTH, zone->domain, NULL, "<AXFR>");
|
||||||
|
}
|
||||||
|
else if (qtype == T_NS)
|
||||||
|
{
|
||||||
|
ns = 1; /* inhibits auth section */
|
||||||
|
found = 1;
|
||||||
|
log_query(F_RRNAME | F_AUTH, zone->domain, NULL, "<NS>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!option_bool(OPT_DHCP_FQDN) && cut)
|
||||||
|
{
|
||||||
|
*cut = 0; /* remove domain part */
|
||||||
|
|
||||||
|
if (!strchr(name, '.') && (crecp = cache_find_by_name(NULL, name, now, F_IPV4 | F_IPV6)))
|
||||||
|
{
|
||||||
|
if (crecp->flags & F_DHCP)
|
||||||
|
do
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
if ((crecp->flags & flag) && filter_zone(zone, flag, &(crecp->addr.addr)))
|
||||||
|
{
|
||||||
|
*cut = '.'; /* restore domain part */
|
||||||
|
log_query(crecp->flags, name, &crecp->addr.addr, record_source(crecp->uid));
|
||||||
|
*cut = 0; /* remove domain part */
|
||||||
|
found = 1;
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, qtype, C_IN,
|
||||||
|
qtype == T_A ? "4" : "6", &crecp->addr))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
} while ((crecp = cache_find_by_name(crecp, name, now, F_IPV4 | F_IPV6)));
|
||||||
|
}
|
||||||
|
|
||||||
|
*cut = '.'; /* restore domain part */
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((crecp = cache_find_by_name(NULL, name, now, F_IPV4 | F_IPV6)))
|
||||||
|
{
|
||||||
|
if ((crecp->flags & F_HOSTS) || (((crecp->flags & F_DHCP) && option_bool(OPT_DHCP_FQDN))))
|
||||||
|
do
|
||||||
|
{
|
||||||
|
nxdomain = 0;
|
||||||
|
if ((crecp->flags & flag) && filter_zone(zone, flag, &(crecp->addr.addr)))
|
||||||
|
{
|
||||||
|
log_query(crecp->flags, name, &crecp->addr.addr, record_source(crecp->uid));
|
||||||
|
found = 1;
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, qtype, C_IN,
|
||||||
|
qtype == T_A ? "4" : "6", &crecp->addr))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
} while ((crecp = cache_find_by_name(crecp, name, now, F_IPV4 | F_IPV6)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
log_query(flag | F_NEG | (nxdomain ? F_NXDOMAIN : 0) | F_FORWARD | F_AUTH, name, NULL, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add auth section */
|
||||||
|
if (auth)
|
||||||
|
{
|
||||||
|
char *authname;
|
||||||
|
int newoffset, offset = 0;
|
||||||
|
|
||||||
|
if (!subnet)
|
||||||
|
authname = zone->domain;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* handle NS and SOA for PTR records */
|
||||||
|
|
||||||
|
authname = name;
|
||||||
|
|
||||||
|
if (!subnet->is6)
|
||||||
|
{
|
||||||
|
in_addr_t a = ntohl(subnet->addr4.s_addr) >> 8;
|
||||||
|
char *p = name;
|
||||||
|
|
||||||
|
if (subnet->prefixlen == 24)
|
||||||
|
p += sprintf(p, "%d.", a & 0xff);
|
||||||
|
a = a >> 8;
|
||||||
|
if (subnet->prefixlen != 8)
|
||||||
|
p += sprintf(p, "%d.", a & 0xff);
|
||||||
|
a = a >> 8;
|
||||||
|
p += sprintf(p, "%d.in-addr.arpa", a & 0xff);
|
||||||
|
|
||||||
|
}
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *p = name;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = subnet->prefixlen-1; i >= 0; i -= 4)
|
||||||
|
{
|
||||||
|
int dig = ((unsigned char *)&subnet->addr6)[i>>3];
|
||||||
|
p += sprintf(p, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4);
|
||||||
|
}
|
||||||
|
p += sprintf(p, "ip6.arpa");
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle NS and SOA in auth section or for explicit queries */
|
||||||
|
newoffset = ansp - (unsigned char *)header;
|
||||||
|
if (((anscount == 0 && !ns) || soa) &&
|
||||||
|
add_resource_record(header, limit, &trunc, 0, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, T_SOA, C_IN, "ddlllll",
|
||||||
|
authname, daemon->authserver, daemon->hostmaster,
|
||||||
|
daemon->soa_sn, daemon->soa_refresh,
|
||||||
|
daemon->soa_retry, daemon->soa_expiry,
|
||||||
|
daemon->auth_ttl))
|
||||||
|
{
|
||||||
|
offset = newoffset;
|
||||||
|
if (soa)
|
||||||
|
anscount++;
|
||||||
|
else
|
||||||
|
authcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anscount != 0 || ns)
|
||||||
|
{
|
||||||
|
struct name_list *secondary;
|
||||||
|
|
||||||
|
newoffset = ansp - (unsigned char *)header;
|
||||||
|
if (add_resource_record(header, limit, &trunc, -offset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, T_NS, C_IN, "d", offset == 0 ? authname : NULL, daemon->authserver))
|
||||||
|
{
|
||||||
|
if (offset == 0)
|
||||||
|
offset = newoffset;
|
||||||
|
if (ns)
|
||||||
|
anscount++;
|
||||||
|
else
|
||||||
|
authcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subnet)
|
||||||
|
for (secondary = daemon->secondary_forward_server; secondary; secondary = secondary->next)
|
||||||
|
if (add_resource_record(header, limit, &trunc, offset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, T_NS, C_IN, "d", secondary->name))
|
||||||
|
{
|
||||||
|
if (ns)
|
||||||
|
anscount++;
|
||||||
|
else
|
||||||
|
authcount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axfr)
|
||||||
|
{
|
||||||
|
for (rec = daemon->mxnames; rec; rec = rec->next)
|
||||||
|
if (in_zone(zone, rec->name, &cut))
|
||||||
|
{
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (rec->issrv)
|
||||||
|
{
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_SRV, C_IN, "sssd", cut ? rec->name : NULL,
|
||||||
|
rec->priority, rec->weight, rec->srvport, rec->target))
|
||||||
|
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_MX, C_IN, "sd", cut ? rec->name : NULL, rec->weight, rec->target))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* restore config data */
|
||||||
|
if (cut)
|
||||||
|
*cut = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (txt = daemon->rr; txt; txt = txt->next)
|
||||||
|
if (in_zone(zone, txt->name, &cut))
|
||||||
|
{
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, txt->class, C_IN, "t", cut ? txt->name : NULL, txt->len, txt->txt))
|
||||||
|
anscount++;
|
||||||
|
|
||||||
|
/* restore config data */
|
||||||
|
if (cut)
|
||||||
|
*cut = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (txt = daemon->txt; txt; txt = txt->next)
|
||||||
|
if (txt->class == C_IN && in_zone(zone, txt->name, &cut))
|
||||||
|
{
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_TXT, C_IN, "t", cut ? txt->name : NULL, txt->len, txt->txt))
|
||||||
|
anscount++;
|
||||||
|
|
||||||
|
/* restore config data */
|
||||||
|
if (cut)
|
||||||
|
*cut = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (na = daemon->naptr; na; na = na->next)
|
||||||
|
if (in_zone(zone, na->name, &cut))
|
||||||
|
{
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp, daemon->auth_ttl,
|
||||||
|
NULL, T_NAPTR, C_IN, "sszzzd", cut ? na->name : NULL,
|
||||||
|
na->order, na->pref, na->flags, na->services, na->regexp, na->replace))
|
||||||
|
anscount++;
|
||||||
|
|
||||||
|
/* restore config data */
|
||||||
|
if (cut)
|
||||||
|
*cut = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (intr = daemon->int_names; intr; intr = intr->next)
|
||||||
|
if (in_zone(zone, intr->name, &cut) && (addr.addr.addr4 = get_ifaddr(intr->intr)).s_addr != (in_addr_t) -1)
|
||||||
|
{
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, T_A, C_IN, "4", cut ? intr->name : NULL, &addr))
|
||||||
|
anscount++;
|
||||||
|
|
||||||
|
/* restore config data */
|
||||||
|
if (cut)
|
||||||
|
*cut = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (a = daemon->cnames; a; a = a->next)
|
||||||
|
if (in_zone(zone, a->alias, &cut))
|
||||||
|
{
|
||||||
|
strcpy(name, a->target);
|
||||||
|
if (!strchr(name, '.'))
|
||||||
|
{
|
||||||
|
strcat(name, ".");
|
||||||
|
strcat(name, zone->domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL,
|
||||||
|
T_CNAME, C_IN, "d", cut ? a->alias : NULL, name))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
cache_enumerate(1);
|
||||||
|
while ((crecp = cache_enumerate(0)))
|
||||||
|
{
|
||||||
|
if ((crecp->flags & (F_IPV4 | F_IPV6)) &&
|
||||||
|
!(crecp->flags & (F_NEG | F_NXDOMAIN)) &&
|
||||||
|
(crecp->flags & F_FORWARD))
|
||||||
|
{
|
||||||
|
if ((crecp->flags & F_DHCP) && !option_bool(OPT_DHCP_FQDN))
|
||||||
|
{
|
||||||
|
char *cache_name = cache_get_name(crecp);
|
||||||
|
if (!strchr(cache_name, '.') && filter_zone(zone, (crecp->flags & (F_IPV6 | F_IPV4)), &(crecp->addr.addr)))
|
||||||
|
{
|
||||||
|
qtype = T_A;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (crecp->flags & F_IPV6)
|
||||||
|
qtype = T_AAAA;
|
||||||
|
#endif
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, qtype, C_IN,
|
||||||
|
(crecp->flags & F_IPV4) ? "4" : "6", cache_name, &crecp->addr))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((crecp->flags & F_HOSTS) || (((crecp->flags & F_DHCP) && option_bool(OPT_DHCP_FQDN))))
|
||||||
|
{
|
||||||
|
strcpy(name, cache_get_name(crecp));
|
||||||
|
if (in_zone(zone, name, &cut) && filter_zone(zone, (crecp->flags & (F_IPV6 | F_IPV4)), &(crecp->addr.addr)))
|
||||||
|
{
|
||||||
|
qtype = T_A;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (crecp->flags & F_IPV6)
|
||||||
|
qtype = T_AAAA;
|
||||||
|
#endif
|
||||||
|
if (cut)
|
||||||
|
*cut = 0;
|
||||||
|
|
||||||
|
if (add_resource_record(header, limit, &trunc, -axfroffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, qtype, C_IN,
|
||||||
|
(crecp->flags & F_IPV4) ? "4" : "6", cut ? name : NULL, &crecp->addr))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* repeat SOA as last record */
|
||||||
|
if (add_resource_record(header, limit, &trunc, axfroffset, &ansp,
|
||||||
|
daemon->auth_ttl, NULL, T_SOA, C_IN, "ddlllll",
|
||||||
|
daemon->authserver, daemon->hostmaster,
|
||||||
|
daemon->soa_sn, daemon->soa_refresh,
|
||||||
|
daemon->soa_retry, daemon->soa_expiry,
|
||||||
|
daemon->auth_ttl))
|
||||||
|
anscount++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* done all questions, set up header and return length of result */
|
||||||
|
/* clear authoritative and truncated flags, set QR flag */
|
||||||
|
header->hb3 = (header->hb3 & ~(HB3_AA | HB3_TC)) | HB3_QR;
|
||||||
|
/* clear RA flag */
|
||||||
|
header->hb4 &= ~HB4_RA;
|
||||||
|
|
||||||
|
/* authoritive */
|
||||||
|
if (auth)
|
||||||
|
header->hb3 |= HB3_AA;
|
||||||
|
|
||||||
|
/* truncation */
|
||||||
|
if (trunc)
|
||||||
|
header->hb3 |= HB3_TC;
|
||||||
|
|
||||||
|
if (anscount == 0 && auth && nxdomain)
|
||||||
|
SET_RCODE(header, NXDOMAIN);
|
||||||
|
else
|
||||||
|
SET_RCODE(header, NOERROR); /* no error */
|
||||||
|
header->ancount = htons(anscount);
|
||||||
|
header->nscount = htons(authcount);
|
||||||
|
header->arcount = htons(0);
|
||||||
|
return ansp - (unsigned char *)header;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,19 +17,10 @@
|
|||||||
#include "dnsmasq.h"
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
#if defined(HAVE_BSD_NETWORK) || defined(HAVE_SOLARIS_NETWORK)
|
#if defined(HAVE_BSD_NETWORK) || defined(HAVE_SOLARIS_NETWORK)
|
||||||
|
#include <ifaddrs.h>
|
||||||
static struct iovec ifconf = {
|
|
||||||
.iov_base = NULL,
|
|
||||||
.iov_len = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct iovec ifreq = {
|
|
||||||
.iov_base = NULL,
|
|
||||||
.iov_len = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__)
|
#if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__)
|
||||||
|
#include <sys/param.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#include <net/if_dl.h>
|
#include <net/if_dl.h>
|
||||||
@@ -50,8 +41,12 @@ int arp_enumerate(void *parm, int (*callback)())
|
|||||||
struct rt_msghdr *rtm;
|
struct rt_msghdr *rtm;
|
||||||
struct sockaddr_inarp *sin2;
|
struct sockaddr_inarp *sin2;
|
||||||
struct sockaddr_dl *sdl;
|
struct sockaddr_dl *sdl;
|
||||||
|
struct iovec buff;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
buff.iov_base = NULL;
|
||||||
|
buff.iov_len = 0;
|
||||||
|
|
||||||
mib[0] = CTL_NET;
|
mib[0] = CTL_NET;
|
||||||
mib[1] = PF_ROUTE;
|
mib[1] = PF_ROUTE;
|
||||||
mib[2] = 0;
|
mib[2] = 0;
|
||||||
@@ -67,9 +62,9 @@ int arp_enumerate(void *parm, int (*callback)())
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (!expand_buf(&ifconf, needed))
|
if (!expand_buf(&buff, needed))
|
||||||
return 0;
|
return 0;
|
||||||
if ((rc = sysctl(mib, 6, ifconf.iov_base, &needed, NULL, 0)) == 0 ||
|
if ((rc = sysctl(mib, 6, buff.iov_base, &needed, NULL, 0)) == 0 ||
|
||||||
errno != ENOMEM)
|
errno != ENOMEM)
|
||||||
break;
|
break;
|
||||||
needed += needed / 8;
|
needed += needed / 8;
|
||||||
@@ -77,7 +72,7 @@ int arp_enumerate(void *parm, int (*callback)())
|
|||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (next = ifconf.iov_base ; next < (char *)ifconf.iov_base + needed; next += rtm->rtm_msglen)
|
for (next = buff.iov_base ; next < (char *)buff.iov_base + needed; next += rtm->rtm_msglen)
|
||||||
{
|
{
|
||||||
rtm = (struct rt_msghdr *)next;
|
rtm = (struct rt_msghdr *)next;
|
||||||
sin2 = (struct sockaddr_inarp *)(rtm + 1);
|
sin2 = (struct sockaddr_inarp *)(rtm + 1);
|
||||||
@@ -88,19 +83,14 @@ int arp_enumerate(void *parm, int (*callback)())
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int iface_enumerate(int family, void *parm, int (*callback)())
|
int iface_enumerate(int family, void *parm, int (*callback)())
|
||||||
{
|
{
|
||||||
char *ptr;
|
struct ifaddrs *head, *addrs;
|
||||||
struct ifreq *ifr;
|
int errsav, ret = 0;
|
||||||
struct ifconf ifc;
|
|
||||||
int fd, errsav, ret = 0;
|
|
||||||
int lastlen = 0;
|
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
if (family == AF_UNSPEC)
|
if (family == AF_UNSPEC)
|
||||||
#if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__)
|
#if defined(HAVE_BSD_NETWORK) && !defined(__APPLE__)
|
||||||
return arp_enumerate(parm, callback);
|
return arp_enumerate(parm, callback);
|
||||||
@@ -108,88 +98,69 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
return 0; /* need code for Solaris and MacOS*/
|
return 0; /* need code for Solaris and MacOS*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
|
/* AF_LINK doesn't exist in Linux, so we can't use it in our API */
|
||||||
|
if (family == AF_LOCAL)
|
||||||
|
family = AF_LINK;
|
||||||
|
|
||||||
|
if (getifaddrs(&head) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
len += 10*sizeof(struct ifreq);
|
|
||||||
|
|
||||||
if (!expand_buf(&ifconf, len))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
ifc.ifc_len = len;
|
|
||||||
ifc.ifc_buf = ifconf.iov_base;
|
|
||||||
|
|
||||||
if (ioctl(fd, SIOCGIFCONF, &ifc) == -1)
|
|
||||||
{
|
|
||||||
if (errno != EINVAL || lastlen != 0)
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ifc.ifc_len == lastlen)
|
|
||||||
break; /* got a big enough buffer now */
|
|
||||||
lastlen = ifc.ifc_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ptr = ifc.ifc_buf; ptr < (char *)(ifc.ifc_buf + ifc.ifc_len); ptr += len)
|
|
||||||
{
|
|
||||||
/* subsequent entries may not be aligned, so copy into
|
|
||||||
an aligned buffer to avoid nasty complaints about
|
|
||||||
unaligned accesses. */
|
|
||||||
|
|
||||||
len = sizeof(struct ifreq);
|
for (addrs = head; addrs; addrs = addrs->ifa_next)
|
||||||
|
{
|
||||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
if (addrs->ifa_addr->sa_family == family)
|
||||||
ifr = (struct ifreq *)ptr;
|
|
||||||
if (ifr->ifr_addr.sa_len > sizeof(ifr->ifr_ifru))
|
|
||||||
len = ifr->ifr_addr.sa_len + offsetof(struct ifreq, ifr_ifru);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!expand_buf(&ifreq, len))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
ifr = (struct ifreq *)ifreq.iov_base;
|
|
||||||
memcpy(ifr, ptr, len);
|
|
||||||
|
|
||||||
if (ifr->ifr_addr.sa_family == family)
|
|
||||||
{
|
{
|
||||||
|
int iface_index = if_nametoindex(addrs->ifa_name);
|
||||||
|
|
||||||
|
if (iface_index == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (family == AF_INET)
|
if (family == AF_INET)
|
||||||
{
|
{
|
||||||
struct in_addr addr, netmask, broadcast;
|
struct in_addr addr, netmask, broadcast;
|
||||||
broadcast.s_addr = 0;
|
addr = ((struct sockaddr_in *) addrs->ifa_addr)->sin_addr;
|
||||||
addr = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr;
|
netmask = ((struct sockaddr_in *) addrs->ifa_netmask)->sin_addr;
|
||||||
if (ioctl(fd, SIOCGIFNETMASK, ifr) == -1)
|
broadcast = ((struct sockaddr_in *) addrs->ifa_broadaddr)->sin_addr;
|
||||||
continue;
|
if (!((*callback)(addr, iface_index, netmask, broadcast, parm)))
|
||||||
netmask = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr;
|
|
||||||
if (ioctl(fd, SIOCGIFBRDADDR, ifr) != -1)
|
|
||||||
broadcast = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr;
|
|
||||||
if (!((*callback)(addr,
|
|
||||||
(int)if_nametoindex(ifr->ifr_name),
|
|
||||||
netmask, broadcast,
|
|
||||||
parm)))
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
else if (family == AF_INET6)
|
else if (family == AF_INET6)
|
||||||
{
|
{
|
||||||
struct in6_addr *addr = &((struct sockaddr_in6 *)&ifr->ifr_addr)->sin6_addr;
|
struct in6_addr *addr = &((struct sockaddr_in6 *) addrs->ifa_addr)->sin6_addr;
|
||||||
|
unsigned char *netmask = (unsigned char *) &((struct sockaddr_in6 *) addrs->ifa_netmask)->sin6_addr;
|
||||||
|
int scope_id = ((struct sockaddr_in6 *) addrs->ifa_addr)->sin6_scope_id;
|
||||||
|
int i, j, prefix = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < IN6ADDRSZ; i++, prefix += 8)
|
||||||
|
if (netmask[i] != 0xff)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (i != IN6ADDRSZ && netmask[i])
|
||||||
|
for (j = 7; j > 0; j--, prefix++)
|
||||||
|
if ((netmask[i] & (1 << j)) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
/* voodoo to clear interface field in address */
|
/* voodoo to clear interface field in address */
|
||||||
if (!option_bool(OPT_NOWILD) && IN6_IS_ADDR_LINKLOCAL(addr))
|
if (!option_bool(OPT_NOWILD) && IN6_IS_ADDR_LINKLOCAL(addr))
|
||||||
{
|
{
|
||||||
addr->s6_addr[2] = 0;
|
addr->s6_addr[2] = 0;
|
||||||
addr->s6_addr[3] = 0;
|
addr->s6_addr[3] = 0;
|
||||||
}
|
}
|
||||||
/* We have no way to determine the prefix, so we assume it's 64 for now....... */
|
|
||||||
if (!((*callback)(addr, 64,
|
if (!((*callback)(addr, prefix, scope_id, iface_index, 0, 0, 0, parm)))
|
||||||
(int)((struct sockaddr_in6 *)&ifr->ifr_addr)->sin6_scope_id,
|
goto err;
|
||||||
(int)if_nametoindex(ifr->ifr_name), 0,
|
}
|
||||||
parm)))
|
#endif
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
else if (family == AF_LINK)
|
||||||
|
{
|
||||||
|
/* Assume ethernet again here */
|
||||||
|
struct sockaddr_dl *sdl = (struct sockaddr_dl *) addrs->ifa_addr;
|
||||||
|
if (sdl->sdl_alen != 0 &&
|
||||||
|
!((*callback)(iface_index, ARPHRD_ETHER, LLADDR(sdl), sdl->sdl_alen, parm)))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +168,7 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
errsav = errno;
|
errsav = errno;
|
||||||
close(fd);
|
freeifaddrs(head);
|
||||||
errno = errsav;
|
errno = errsav;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -214,13 +185,10 @@ void init_bpf(void)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* useful size which happens to be sufficient */
|
sprintf(daemon->dhcp_buff, "/dev/bpf%d", i++);
|
||||||
if (expand_buf(&ifreq, sizeof(struct ifreq)))
|
if ((daemon->dhcp_raw_fd = open(daemon->dhcp_buff, O_RDWR, 0)) != -1)
|
||||||
{
|
return;
|
||||||
sprintf(ifreq.iov_base, "/dev/bpf%d", i++);
|
|
||||||
if ((daemon->dhcp_raw_fd = open(ifreq.iov_base, O_RDWR, 0)) != -1)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (errno != EBUSY)
|
if (errno != EBUSY)
|
||||||
die(_("cannot create DHCP BPF socket: %s"), NULL, EC_BADNET);
|
die(_("cannot create DHCP BPF socket: %s"), NULL, EC_BADNET);
|
||||||
}
|
}
|
||||||
|
|||||||
+288
-122
@@ -25,6 +25,9 @@ static int cache_inserted = 0, cache_live_freed = 0, insert_error;
|
|||||||
static union bigname *big_free = NULL;
|
static union bigname *big_free = NULL;
|
||||||
static int bignames_left, hash_size;
|
static int bignames_left, hash_size;
|
||||||
static int uid = 0;
|
static int uid = 0;
|
||||||
|
#ifdef HAVE_DNSSEC
|
||||||
|
static struct keydata *keyblock_free = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* type->string mapping: this is also used by the name-hash function as a mixing table. */
|
/* type->string mapping: this is also used by the name-hash function as a mixing table. */
|
||||||
static const struct {
|
static const struct {
|
||||||
@@ -190,6 +193,10 @@ static void cache_free(struct crec *crecp)
|
|||||||
big_free = crecp->name.bname;
|
big_free = crecp->name.bname;
|
||||||
crecp->flags &= ~F_BIGNAME;
|
crecp->flags &= ~F_BIGNAME;
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_DNSSEC
|
||||||
|
else if (crecp->flags & (F_DNSKEY | F_DS))
|
||||||
|
keydata_free(crecp->addr.key.keydata);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* insert a new cache entry at the head of the list (youngest entry) */
|
/* insert a new cache entry at the head of the list (youngest entry) */
|
||||||
@@ -228,12 +235,39 @@ char *cache_get_name(struct crec *crecp)
|
|||||||
return crecp->name.sname;
|
return crecp->name.sname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct crec *cache_enumerate(int init)
|
||||||
|
{
|
||||||
|
static int bucket;
|
||||||
|
static struct crec *cache;
|
||||||
|
|
||||||
|
if (init)
|
||||||
|
{
|
||||||
|
bucket = 0;
|
||||||
|
cache = NULL;
|
||||||
|
}
|
||||||
|
else if (cache && cache->hash_next)
|
||||||
|
cache = cache->hash_next;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cache = NULL;
|
||||||
|
while (bucket < hash_size)
|
||||||
|
if ((cache = hash_table[bucket++]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
static int is_outdated_cname_pointer(struct crec *crecp)
|
static int is_outdated_cname_pointer(struct crec *crecp)
|
||||||
{
|
{
|
||||||
if (!(crecp->flags & F_CNAME))
|
if (!(crecp->flags & F_CNAME))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (crecp->addr.cname.cache && crecp->addr.cname.uid == crecp->addr.cname.cache->uid)
|
/* NB. record may be reused as DS or DNSKEY, where uid is
|
||||||
|
overloaded for something completely different */
|
||||||
|
if (crecp->addr.cname.cache &&
|
||||||
|
(crecp->addr.cname.cache->flags & (F_IPV4 | F_IPV6 | F_CNAME)) &&
|
||||||
|
crecp->addr.cname.uid == crecp->addr.cname.cache->uid)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -280,7 +314,7 @@ static int cache_scan_free(char *name, struct all_addr *addr, time_t now, unsign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((crecp->flags & F_FORWARD) &&
|
else if ((crecp->flags & F_FORWARD) &&
|
||||||
((flags & crecp->flags & (F_IPV4 | F_IPV6)) || ((crecp->flags | flags) & F_CNAME)) &&
|
((flags & crecp->flags & F_TYPE) || ((crecp->flags | flags) & F_CNAME)) &&
|
||||||
hostname_isequal(cache_get_name(crecp), name))
|
hostname_isequal(cache_get_name(crecp), name))
|
||||||
{
|
{
|
||||||
if (crecp->flags & (F_HOSTS | F_DHCP))
|
if (crecp->flags & (F_HOSTS | F_DHCP))
|
||||||
@@ -360,7 +394,12 @@ struct crec *cache_insert(char *name, struct all_addr *addr,
|
|||||||
int freed_all = flags & F_REVERSE;
|
int freed_all = flags & F_REVERSE;
|
||||||
int free_avail = 0;
|
int free_avail = 0;
|
||||||
|
|
||||||
log_query(flags | F_UPSTREAM, name, addr, NULL);
|
if (daemon->max_cache_ttl != 0 && daemon->max_cache_ttl < ttl)
|
||||||
|
ttl = daemon->max_cache_ttl;
|
||||||
|
|
||||||
|
/* Don't log keys */
|
||||||
|
if (flags & (F_IPV4 | F_IPV6))
|
||||||
|
log_query(flags | F_UPSTREAM, name, addr, NULL);
|
||||||
|
|
||||||
/* if previous insertion failed give up now. */
|
/* if previous insertion failed give up now. */
|
||||||
if (insert_error)
|
if (insert_error)
|
||||||
@@ -452,9 +491,7 @@ struct crec *cache_insert(char *name, struct all_addr *addr,
|
|||||||
|
|
||||||
if (addr)
|
if (addr)
|
||||||
new->addr.addr = *addr;
|
new->addr.addr = *addr;
|
||||||
else
|
|
||||||
new->addr.cname.cache = NULL;
|
|
||||||
|
|
||||||
new->ttd = now + (time_t)ttl;
|
new->ttd = now + (time_t)ttl;
|
||||||
new->next = new_chain;
|
new->next = new_chain;
|
||||||
new_chain = new;
|
new_chain = new;
|
||||||
@@ -634,12 +671,29 @@ struct crec *cache_find_by_addr(struct crec *crecp, struct all_addr *addr,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_hosts_entry(struct crec *cache, struct all_addr *addr, int addrlen,
|
static void add_hosts_cname(struct crec *target)
|
||||||
unsigned short flags, int index, struct crec **rhash)
|
|
||||||
{
|
{
|
||||||
struct crec *lookup = cache_find_by_name(NULL, cache->name.sname, 0, flags & (F_IPV4 | F_IPV6));
|
struct crec *crec;
|
||||||
int i, nameexists = 0;
|
|
||||||
struct cname *a;
|
struct cname *a;
|
||||||
|
|
||||||
|
for (a = daemon->cnames; a; a = a->next)
|
||||||
|
if (hostname_isequal(cache_get_name(target), a->target) &&
|
||||||
|
(crec = whine_malloc(sizeof(struct crec))))
|
||||||
|
{
|
||||||
|
crec->flags = F_FORWARD | F_IMMORTAL | F_NAMEP | F_HOSTS | F_CNAME;
|
||||||
|
crec->name.namep = a->alias;
|
||||||
|
crec->addr.cname.cache = target;
|
||||||
|
crec->addr.cname.uid = target->uid;
|
||||||
|
cache_hash(crec);
|
||||||
|
add_hosts_cname(crec); /* handle chains */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_hosts_entry(struct crec *cache, struct all_addr *addr, int addrlen,
|
||||||
|
int index, struct crec **rhash, int hashsz)
|
||||||
|
{
|
||||||
|
struct crec *lookup = cache_find_by_name(NULL, cache_get_name(cache), 0, cache->flags & (F_IPV4 | F_IPV6));
|
||||||
|
int i, nameexists = 0;
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
|
||||||
/* Remove duplicates in hosts files. */
|
/* Remove duplicates in hosts files. */
|
||||||
@@ -656,27 +710,24 @@ static void add_hosts_entry(struct crec *cache, struct all_addr *addr, int addrl
|
|||||||
/* Ensure there is only one address -> name mapping (first one trumps)
|
/* Ensure there is only one address -> name mapping (first one trumps)
|
||||||
We do this by steam here, The entries are kept in hash chains, linked
|
We do this by steam here, The entries are kept in hash chains, linked
|
||||||
by ->next (which is unused at this point) held in hash buckets in
|
by ->next (which is unused at this point) held in hash buckets in
|
||||||
the array rhash. Note that rhash and the values in ->next are only valid
|
the array rhash, hashed on address. Note that rhash and the values
|
||||||
whilst reading hosts files: the buckets are then freed, and the
|
in ->next are only valid whilst reading hosts files: the buckets are
|
||||||
->next pointer used for other things.
|
then freed, and the ->next pointer used for other things.
|
||||||
|
|
||||||
Only insert each unique address one into this hashing structure.
|
Only insert each unique address once into this hashing structure.
|
||||||
|
|
||||||
This complexity avoids O(n^2) divergent CPU use whilst reading
|
This complexity avoids O(n^2) divergent CPU use whilst reading
|
||||||
large (10000 entry) hosts files. */
|
large (10000 entry) hosts files. */
|
||||||
|
|
||||||
/* hash address */
|
/* hash address */
|
||||||
for (j = 0, i = 0; i < addrlen; i++)
|
for (j = 0, i = 0; i < addrlen; i++)
|
||||||
j += ((unsigned char *)addr)[i] + (j << 6) + (j << 16) - j;
|
j = (j*2 +((unsigned char *)addr)[i]) % hashsz;
|
||||||
|
|
||||||
j = j % RHASHSIZE;
|
|
||||||
|
|
||||||
for (lookup = rhash[j]; lookup; lookup = lookup->next)
|
for (lookup = rhash[j]; lookup; lookup = lookup->next)
|
||||||
if ((lookup->flags & F_HOSTS) &&
|
if ((lookup->flags & cache->flags & (F_IPV4 | F_IPV6)) &&
|
||||||
(lookup->flags & flags & (F_IPV4 | F_IPV6)) &&
|
|
||||||
memcmp(&lookup->addr.addr, addr, addrlen) == 0)
|
memcmp(&lookup->addr.addr, addr, addrlen) == 0)
|
||||||
{
|
{
|
||||||
flags &= ~F_REVERSE;
|
cache->flags &= ~F_REVERSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,23 +738,13 @@ static void add_hosts_entry(struct crec *cache, struct all_addr *addr, int addrl
|
|||||||
rhash[j] = cache;
|
rhash[j] = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache->flags = flags;
|
|
||||||
cache->uid = index;
|
cache->uid = index;
|
||||||
memcpy(&cache->addr.addr, addr, addrlen);
|
memcpy(&cache->addr.addr, addr, addrlen);
|
||||||
cache_hash(cache);
|
cache_hash(cache);
|
||||||
|
|
||||||
/* don't need to do alias stuff for second and subsequent addresses. */
|
/* don't need to do alias stuff for second and subsequent addresses. */
|
||||||
if (!nameexists)
|
if (!nameexists)
|
||||||
for (a = daemon->cnames; a; a = a->next)
|
add_hosts_cname(cache);
|
||||||
if (hostname_isequal(cache->name.sname, a->target) &&
|
|
||||||
(lookup = whine_malloc(sizeof(struct crec))))
|
|
||||||
{
|
|
||||||
lookup->flags = F_FORWARD | F_IMMORTAL | F_NAMEP | F_HOSTS | F_CNAME;
|
|
||||||
lookup->name.namep = a->alias;
|
|
||||||
lookup->addr.cname.cache = cache;
|
|
||||||
lookup->addr.cname.uid = index;
|
|
||||||
cache_hash(lookup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int eatspace(FILE *f)
|
static int eatspace(FILE *f)
|
||||||
@@ -753,7 +794,7 @@ static int gettok(FILE *f, char *token)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_hostsfile(char *filename, int index, int cache_size, struct crec **rhash)
|
static int read_hostsfile(char *filename, int index, int cache_size, struct crec **rhash, int hashsz)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(filename, "r");
|
FILE *f = fopen(filename, "r");
|
||||||
char *token = daemon->namebuff, *domain_suffix = NULL;
|
char *token = daemon->namebuff, *domain_suffix = NULL;
|
||||||
@@ -774,25 +815,18 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
|
|||||||
{
|
{
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|
||||||
#ifdef HAVE_IPV6
|
|
||||||
if (inet_pton(AF_INET, token, &addr) > 0)
|
if (inet_pton(AF_INET, token, &addr) > 0)
|
||||||
{
|
{
|
||||||
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
|
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
|
||||||
addrlen = INADDRSZ;
|
addrlen = INADDRSZ;
|
||||||
domain_suffix = get_domain(addr.addr.addr4);
|
domain_suffix = get_domain(addr.addr.addr4);
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
else if (inet_pton(AF_INET6, token, &addr) > 0)
|
else if (inet_pton(AF_INET6, token, &addr) > 0)
|
||||||
{
|
{
|
||||||
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV6;
|
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV6;
|
||||||
addrlen = IN6ADDRSZ;
|
addrlen = IN6ADDRSZ;
|
||||||
domain_suffix = daemon->domain_suffix;
|
domain_suffix = get_domain6(&addr.addr.addr6);
|
||||||
}
|
|
||||||
#else
|
|
||||||
if ((addr.addr.addr4.s_addr = inet_addr(token)) != (in_addr_t) -1)
|
|
||||||
{
|
|
||||||
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
|
|
||||||
addrlen = INADDRSZ;
|
|
||||||
domain_suffix = get_domain(addr.addr.addr4);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
@@ -833,13 +867,15 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
|
|||||||
strcpy(cache->name.sname, canon);
|
strcpy(cache->name.sname, canon);
|
||||||
strcat(cache->name.sname, ".");
|
strcat(cache->name.sname, ".");
|
||||||
strcat(cache->name.sname, domain_suffix);
|
strcat(cache->name.sname, domain_suffix);
|
||||||
add_hosts_entry(cache, &addr, addrlen, flags, index, rhash);
|
cache->flags = flags;
|
||||||
|
add_hosts_entry(cache, &addr, addrlen, index, rhash, hashsz);
|
||||||
name_count++;
|
name_count++;
|
||||||
}
|
}
|
||||||
if ((cache = whine_malloc(sizeof(struct crec) + strlen(canon)+1-SMALLDNAME)))
|
if ((cache = whine_malloc(sizeof(struct crec) + strlen(canon)+1-SMALLDNAME)))
|
||||||
{
|
{
|
||||||
strcpy(cache->name.sname, canon);
|
strcpy(cache->name.sname, canon);
|
||||||
add_hosts_entry(cache, &addr, addrlen, flags, index, rhash);
|
cache->flags = flags;
|
||||||
|
add_hosts_entry(cache, &addr, addrlen, index, rhash, hashsz);
|
||||||
name_count++;
|
name_count++;
|
||||||
}
|
}
|
||||||
free(canon);
|
free(canon);
|
||||||
@@ -861,9 +897,10 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
|
|||||||
void cache_reload(void)
|
void cache_reload(void)
|
||||||
{
|
{
|
||||||
struct crec *cache, **up, *tmp;
|
struct crec *cache, **up, *tmp;
|
||||||
int i, total_size = daemon->cachesize;
|
int revhashsz, i, total_size = daemon->cachesize;
|
||||||
struct hostsfile *ah;
|
struct hostsfile *ah;
|
||||||
struct crec **reverse_hash;
|
struct host_record *hr;
|
||||||
|
struct name_list *nl;
|
||||||
|
|
||||||
cache_inserted = cache_live_freed = 0;
|
cache_inserted = cache_live_freed = 0;
|
||||||
|
|
||||||
@@ -890,28 +927,48 @@ void cache_reload(void)
|
|||||||
up = &cache->hash_next;
|
up = &cache->hash_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* borrow the packet buffer for a temporary by-address hash */
|
||||||
|
memset(daemon->packet, 0, daemon->packet_buff_sz);
|
||||||
|
revhashsz = daemon->packet_buff_sz / sizeof(struct crec *);
|
||||||
|
/* we overwrote the buffer... */
|
||||||
|
daemon->srv_save = NULL;
|
||||||
|
|
||||||
|
/* Do host_records in config. */
|
||||||
|
for (hr = daemon->host_records; hr; hr = hr->next)
|
||||||
|
for (nl = hr->names; nl; nl = nl->next)
|
||||||
|
{
|
||||||
|
if (hr->addr.s_addr != 0 &&
|
||||||
|
(cache = whine_malloc(sizeof(struct crec))))
|
||||||
|
{
|
||||||
|
cache->name.namep = nl->name;
|
||||||
|
cache->flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4 | F_NAMEP | F_CONFIG;
|
||||||
|
add_hosts_entry(cache, (struct all_addr *)&hr->addr, INADDRSZ, 0, (struct crec **)daemon->packet, revhashsz);
|
||||||
|
}
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (!IN6_IS_ADDR_UNSPECIFIED(&hr->addr6) &&
|
||||||
|
(cache = whine_malloc(sizeof(struct crec))))
|
||||||
|
{
|
||||||
|
cache->name.namep = nl->name;
|
||||||
|
cache->flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV6 | F_NAMEP | F_CONFIG;
|
||||||
|
add_hosts_entry(cache, (struct all_addr *)&hr->addr6, IN6ADDRSZ, 0, (struct crec **)daemon->packet, revhashsz);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (option_bool(OPT_NO_HOSTS) && !daemon->addn_hosts)
|
if (option_bool(OPT_NO_HOSTS) && !daemon->addn_hosts)
|
||||||
{
|
{
|
||||||
if (daemon->cachesize > 0)
|
if (daemon->cachesize > 0)
|
||||||
my_syslog(LOG_INFO, _("cleared cache"));
|
my_syslog(LOG_INFO, _("cleared cache"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(reverse_hash = whine_malloc(sizeof(struct crec *) * RHASHSIZE)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < RHASHSIZE; i++)
|
|
||||||
reverse_hash[i] = NULL;
|
|
||||||
|
|
||||||
if (!option_bool(OPT_NO_HOSTS))
|
if (!option_bool(OPT_NO_HOSTS))
|
||||||
total_size = read_hostsfile(HOSTSFILE, 0, total_size, reverse_hash);
|
total_size = read_hostsfile(HOSTSFILE, 0, total_size, (struct crec **)daemon->packet, revhashsz);
|
||||||
|
|
||||||
daemon->addn_hosts = expand_filelist(daemon->addn_hosts);
|
daemon->addn_hosts = expand_filelist(daemon->addn_hosts);
|
||||||
for (ah = daemon->addn_hosts; ah; ah = ah->next)
|
for (ah = daemon->addn_hosts; ah; ah = ah->next)
|
||||||
if (!(ah->flags & AH_INACTIVE))
|
if (!(ah->flags & AH_INACTIVE))
|
||||||
total_size = read_hostsfile(ah->fname, ah->index, total_size, reverse_hash);
|
total_size = read_hostsfile(ah->fname, ah->index, total_size, (struct crec **)daemon->packet, revhashsz);
|
||||||
|
|
||||||
free(reverse_hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_domain(struct in_addr addr)
|
char *get_domain(struct in_addr addr)
|
||||||
@@ -919,13 +976,33 @@ char *get_domain(struct in_addr addr)
|
|||||||
struct cond_domain *c;
|
struct cond_domain *c;
|
||||||
|
|
||||||
for (c = daemon->cond_domain; c; c = c->next)
|
for (c = daemon->cond_domain; c; c = c->next)
|
||||||
if (ntohl(addr.s_addr) >= ntohl(c->start.s_addr) &&
|
if (!c->is6 &&
|
||||||
|
ntohl(addr.s_addr) >= ntohl(c->start.s_addr) &&
|
||||||
ntohl(addr.s_addr) <= ntohl(c->end.s_addr))
|
ntohl(addr.s_addr) <= ntohl(c->end.s_addr))
|
||||||
return c->domain;
|
return c->domain;
|
||||||
|
|
||||||
return daemon->domain_suffix;
|
return daemon->domain_suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
char *get_domain6(struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
struct cond_domain *c;
|
||||||
|
|
||||||
|
u64 addrpart = addr6part(addr);
|
||||||
|
|
||||||
|
for (c = daemon->cond_domain; c; c = c->next)
|
||||||
|
if (c->is6 &&
|
||||||
|
is_same_net6(addr, &c->start6, 64) &&
|
||||||
|
addrpart >= addr6part(&c->start6) &&
|
||||||
|
addrpart <= addr6part(&c->end6))
|
||||||
|
return c->domain;
|
||||||
|
|
||||||
|
return daemon->domain_suffix;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
struct in_addr a_record_from_hosts(char *name, time_t now)
|
struct in_addr a_record_from_hosts(char *name, time_t now)
|
||||||
{
|
{
|
||||||
@@ -959,94 +1036,120 @@ void cache_unhash_dhcp(void)
|
|||||||
up = &cache->hash_next;
|
up = &cache->hash_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cache_add_dhcp_entry(char *host_name,
|
static void add_dhcp_cname(struct crec *target, time_t ttd)
|
||||||
struct in_addr *host_address, time_t ttd)
|
|
||||||
{
|
{
|
||||||
struct crec *crec = NULL, *aliasc;
|
struct crec *aliasc;
|
||||||
unsigned short flags = F_NAMEP | F_DHCP | F_FORWARD | F_IPV4 | F_REVERSE;
|
|
||||||
int in_hosts = 0;
|
|
||||||
struct cname *a;
|
struct cname *a;
|
||||||
|
|
||||||
while ((crec = cache_find_by_name(crec, host_name, 0, F_IPV4 | F_CNAME)))
|
for (a = daemon->cnames; a; a = a->next)
|
||||||
|
if (hostname_isequal(cache_get_name(target), a->target))
|
||||||
|
{
|
||||||
|
if ((aliasc = dhcp_spare))
|
||||||
|
dhcp_spare = dhcp_spare->next;
|
||||||
|
else /* need new one */
|
||||||
|
aliasc = whine_malloc(sizeof(struct crec));
|
||||||
|
|
||||||
|
if (aliasc)
|
||||||
|
{
|
||||||
|
aliasc->flags = F_FORWARD | F_NAMEP | F_DHCP | F_CNAME;
|
||||||
|
if (ttd == 0)
|
||||||
|
aliasc->flags |= F_IMMORTAL;
|
||||||
|
else
|
||||||
|
aliasc->ttd = ttd;
|
||||||
|
aliasc->name.namep = a->alias;
|
||||||
|
aliasc->addr.cname.cache = target;
|
||||||
|
aliasc->addr.cname.uid = target->uid;
|
||||||
|
cache_hash(aliasc);
|
||||||
|
add_dhcp_cname(aliasc, ttd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cache_add_dhcp_entry(char *host_name, int prot,
|
||||||
|
struct all_addr *host_address, time_t ttd)
|
||||||
|
{
|
||||||
|
struct crec *crec = NULL, *fail_crec = NULL;
|
||||||
|
unsigned short flags = F_IPV4;
|
||||||
|
int in_hosts = 0;
|
||||||
|
size_t addrlen = sizeof(struct in_addr);
|
||||||
|
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (prot == AF_INET6)
|
||||||
|
{
|
||||||
|
flags = F_IPV6;
|
||||||
|
addrlen = sizeof(struct in6_addr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inet_ntop(prot, host_address, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
|
||||||
|
while ((crec = cache_find_by_name(crec, host_name, 0, flags | F_CNAME)))
|
||||||
{
|
{
|
||||||
/* check all addresses associated with name */
|
/* check all addresses associated with name */
|
||||||
if (crec->flags & F_HOSTS)
|
if (crec->flags & F_HOSTS)
|
||||||
{
|
{
|
||||||
/* if in hosts, don't need DHCP record */
|
|
||||||
in_hosts = 1;
|
|
||||||
|
|
||||||
if (crec->flags & F_CNAME)
|
if (crec->flags & F_CNAME)
|
||||||
my_syslog(MS_DHCP | LOG_WARNING,
|
my_syslog(MS_DHCP | LOG_WARNING,
|
||||||
_("%s is a CNAME, not giving it to the DHCP lease of %s"),
|
_("%s is a CNAME, not giving it to the DHCP lease of %s"),
|
||||||
host_name, inet_ntoa(*host_address));
|
host_name, daemon->addrbuff);
|
||||||
else if (crec->addr.addr.addr.addr4.s_addr != host_address->s_addr)
|
else if (memcmp(&crec->addr.addr, host_address, addrlen) == 0)
|
||||||
{
|
in_hosts = 1;
|
||||||
strcpy(daemon->namebuff, inet_ntoa(crec->addr.addr.addr.addr4));
|
else
|
||||||
my_syslog(MS_DHCP | LOG_WARNING,
|
fail_crec = crec;
|
||||||
_("not giving name %s to the DHCP lease of %s because "
|
|
||||||
"the name exists in %s with address %s"),
|
|
||||||
host_name, inet_ntoa(*host_address),
|
|
||||||
record_source(crec->uid), daemon->namebuff);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (!(crec->flags & F_DHCP))
|
else if (!(crec->flags & F_DHCP))
|
||||||
{
|
{
|
||||||
cache_scan_free(host_name, NULL, 0, crec->flags & (F_IPV4 | F_CNAME | F_FORWARD));
|
cache_scan_free(host_name, NULL, 0, crec->flags & (flags | F_CNAME | F_FORWARD));
|
||||||
/* scan_free deletes all addresses associated with name */
|
/* scan_free deletes all addresses associated with name */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_hosts)
|
/* if in hosts, don't need DHCP record */
|
||||||
|
if (in_hosts)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((crec = cache_find_by_addr(NULL, (struct all_addr *)host_address, 0, F_IPV4)))
|
/* Name in hosts, address doesn't match */
|
||||||
{
|
if (fail_crec)
|
||||||
if (crec->flags & F_NEG)
|
{
|
||||||
cache_scan_free(NULL, (struct all_addr *)host_address, 0, F_IPV4 | F_REVERSE);
|
inet_ntop(prot, &fail_crec->addr.addr, daemon->namebuff, MAXDNAME);
|
||||||
else
|
my_syslog(MS_DHCP | LOG_WARNING,
|
||||||
/* avoid multiple reverse mappings */
|
_("not giving name %s to the DHCP lease of %s because "
|
||||||
flags &= ~F_REVERSE;
|
"the name exists in %s with address %s"),
|
||||||
}
|
host_name, daemon->addrbuff,
|
||||||
|
record_source(fail_crec->uid), daemon->namebuff);
|
||||||
if ((crec = dhcp_spare))
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((crec = cache_find_by_addr(NULL, (struct all_addr *)host_address, 0, flags)))
|
||||||
|
{
|
||||||
|
if (crec->flags & F_NEG)
|
||||||
|
{
|
||||||
|
flags |= F_REVERSE;
|
||||||
|
cache_scan_free(NULL, (struct all_addr *)host_address, 0, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
flags |= F_REVERSE;
|
||||||
|
|
||||||
|
if ((crec = dhcp_spare))
|
||||||
dhcp_spare = dhcp_spare->next;
|
dhcp_spare = dhcp_spare->next;
|
||||||
else /* need new one */
|
else /* need new one */
|
||||||
crec = whine_malloc(sizeof(struct crec));
|
crec = whine_malloc(sizeof(struct crec));
|
||||||
|
|
||||||
if (crec) /* malloc may fail */
|
if (crec) /* malloc may fail */
|
||||||
{
|
{
|
||||||
crec->flags = flags;
|
crec->flags = flags | F_NAMEP | F_DHCP | F_FORWARD;
|
||||||
if (ttd == 0)
|
if (ttd == 0)
|
||||||
crec->flags |= F_IMMORTAL;
|
crec->flags |= F_IMMORTAL;
|
||||||
else
|
else
|
||||||
crec->ttd = ttd;
|
crec->ttd = ttd;
|
||||||
crec->addr.addr.addr.addr4 = *host_address;
|
crec->addr.addr = *host_address;
|
||||||
crec->name.namep = host_name;
|
crec->name.namep = host_name;
|
||||||
crec->uid = uid++;
|
crec->uid = uid++;
|
||||||
cache_hash(crec);
|
cache_hash(crec);
|
||||||
|
|
||||||
for (a = daemon->cnames; a; a = a->next)
|
add_dhcp_cname(crec, ttd);
|
||||||
if (hostname_isequal(host_name, a->target))
|
|
||||||
{
|
|
||||||
if ((aliasc = dhcp_spare))
|
|
||||||
dhcp_spare = dhcp_spare->next;
|
|
||||||
else /* need new one */
|
|
||||||
aliasc = whine_malloc(sizeof(struct crec));
|
|
||||||
|
|
||||||
if (aliasc)
|
|
||||||
{
|
|
||||||
aliasc->flags = F_FORWARD | F_NAMEP | F_DHCP | F_CNAME;
|
|
||||||
if (ttd == 0)
|
|
||||||
aliasc->flags |= F_IMMORTAL;
|
|
||||||
else
|
|
||||||
aliasc->ttd = ttd;
|
|
||||||
aliasc->name.namep = a->alias;
|
|
||||||
aliasc->addr.cname.cache = crec;
|
|
||||||
aliasc->addr.cname.uid = crec->uid;
|
|
||||||
cache_hash(aliasc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1104,22 +1207,35 @@ void dump_cache(time_t now)
|
|||||||
if (!is_outdated_cname_pointer(cache))
|
if (!is_outdated_cname_pointer(cache))
|
||||||
a = cache_get_name(cache->addr.cname.cache);
|
a = cache_get_name(cache->addr.cname.cache);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_DNSSEC
|
||||||
|
else if (cache->flags & F_DNSKEY)
|
||||||
|
{
|
||||||
|
a = daemon->addrbuff;
|
||||||
|
sprintf(a, "%3u %u", cache->addr.key.algo, cache->uid);
|
||||||
|
}
|
||||||
|
else if (cache->flags & F_DS)
|
||||||
|
{
|
||||||
|
a = daemon->addrbuff;
|
||||||
|
sprintf(a, "%5u %3u %3u %u", cache->addr.key.flags_or_keyid,
|
||||||
|
cache->addr.key.algo, cache->addr.key.digest, cache->uid);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
a = daemon->addrbuff;
|
a = daemon->addrbuff;
|
||||||
if (cache->flags & F_IPV4)
|
if (cache->flags & F_IPV4)
|
||||||
inet_ntop(AF_INET, &cache->addr.addr, a, ADDRSTRLEN);
|
inet_ntop(AF_INET, &cache->addr.addr, a, ADDRSTRLEN);
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
else if (cache->flags & F_IPV6)
|
else if (cache->flags & F_IPV6)
|
||||||
inet_ntop(AF_INET6, &cache->addr.addr, a, ADDRSTRLEN);
|
inet_ntop(AF_INET6, &cache->addr.addr, a, ADDRSTRLEN);
|
||||||
}
|
|
||||||
#else
|
|
||||||
else
|
|
||||||
a = inet_ntoa(cache->addr.addr.addr.addr4);
|
|
||||||
#endif
|
#endif
|
||||||
p += sprintf(p, "%-30.30s %s%s%s%s%s%s%s%s%s%s ", a,
|
}
|
||||||
|
|
||||||
|
p += sprintf(p, "%-30.30s %s%s%s%s%s%s%s%s%s%s%s%s%s ", a,
|
||||||
cache->flags & F_IPV4 ? "4" : "",
|
cache->flags & F_IPV4 ? "4" : "",
|
||||||
cache->flags & F_IPV6 ? "6" : "",
|
cache->flags & F_IPV6 ? "6" : "",
|
||||||
|
cache->flags & F_DNSKEY ? "K" : "",
|
||||||
|
cache->flags & F_DS ? "S" : "",
|
||||||
cache->flags & F_CNAME ? "C" : "",
|
cache->flags & F_CNAME ? "C" : "",
|
||||||
cache->flags & F_FORWARD ? "F" : " ",
|
cache->flags & F_FORWARD ? "F" : " ",
|
||||||
cache->flags & F_REVERSE ? "R" : " ",
|
cache->flags & F_REVERSE ? "R" : " ",
|
||||||
@@ -1127,7 +1243,8 @@ void dump_cache(time_t now)
|
|||||||
cache->flags & F_DHCP ? "D" : " ",
|
cache->flags & F_DHCP ? "D" : " ",
|
||||||
cache->flags & F_NEG ? "N" : " ",
|
cache->flags & F_NEG ? "N" : " ",
|
||||||
cache->flags & F_NXDOMAIN ? "X" : " ",
|
cache->flags & F_NXDOMAIN ? "X" : " ",
|
||||||
cache->flags & F_HOSTS ? "H" : " ");
|
cache->flags & F_HOSTS ? "H" : " ",
|
||||||
|
cache->flags & F_DNSSECOK ? "V" : " ");
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
p += sprintf(p, "%lu", cache->flags & F_IMMORTAL ? 0: (unsigned long)(cache->ttd - now));
|
p += sprintf(p, "%lu", cache->flags & F_IMMORTAL ? 0: (unsigned long)(cache->ttd - now));
|
||||||
#else
|
#else
|
||||||
@@ -1154,14 +1271,14 @@ char *record_source(int index)
|
|||||||
return "<unknown>";
|
return "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
void querystr(char *str, unsigned short type)
|
void querystr(char *desc, char *str, unsigned short type)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
sprintf(str, "query[type=%d]", type);
|
sprintf(str, "%s[type=%d]", desc, type);
|
||||||
for (i = 0; i < (sizeof(typestr)/sizeof(typestr[0])); i++)
|
for (i = 0; i < (sizeof(typestr)/sizeof(typestr[0])); i++)
|
||||||
if (typestr[i].type == type)
|
if (typestr[i].type == type)
|
||||||
sprintf(str,"query[%s]", typestr[i].name);
|
sprintf(str,"%s[%s]", desc, typestr[i].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg)
|
void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg)
|
||||||
@@ -1222,6 +1339,8 @@ void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg)
|
|||||||
source = arg;
|
source = arg;
|
||||||
else if (flags & F_UPSTREAM)
|
else if (flags & F_UPSTREAM)
|
||||||
source = "reply";
|
source = "reply";
|
||||||
|
else if (flags & F_AUTH)
|
||||||
|
source = "auth";
|
||||||
else if (flags & F_SERVER)
|
else if (flags & F_SERVER)
|
||||||
{
|
{
|
||||||
source = "forwarded";
|
source = "forwarded";
|
||||||
@@ -1241,3 +1360,50 @@ void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg)
|
|||||||
my_syslog(LOG_INFO, "%s %s %s %s", source, name, verb, dest);
|
my_syslog(LOG_INFO, "%s %s %s %s", source, name, verb, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DNSSEC
|
||||||
|
struct keydata *keydata_alloc(char *data, size_t len)
|
||||||
|
{
|
||||||
|
struct keydata *block, *ret = NULL;
|
||||||
|
struct keydata **prev = &ret;
|
||||||
|
while (len > 0)
|
||||||
|
{
|
||||||
|
if (keyblock_free)
|
||||||
|
{
|
||||||
|
block = keyblock_free;
|
||||||
|
keyblock_free = block->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
block = whine_malloc(sizeof(struct keydata));
|
||||||
|
|
||||||
|
if (!block)
|
||||||
|
{
|
||||||
|
/* failed to alloc, free partial chain */
|
||||||
|
keydata_free(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(block->key, data, len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len);
|
||||||
|
data += KEYBLOCK_LEN;
|
||||||
|
len -= KEYBLOCK_LEN;
|
||||||
|
*prev = block;
|
||||||
|
prev = &block->next;
|
||||||
|
block->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void keydata_free(struct keydata *blocks)
|
||||||
|
{
|
||||||
|
struct keydata *tmp;
|
||||||
|
|
||||||
|
if (blocks)
|
||||||
|
{
|
||||||
|
for (tmp = blocks; tmp->next; tmp = tmp->next);
|
||||||
|
tmp->next = keyblock_free;
|
||||||
|
keyblock_free = blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
+31
-8
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define FTABSIZ 150 /* max number of outstanding requests (default) */
|
#define FTABSIZ 150 /* max number of outstanding requests (default) */
|
||||||
#define RHASHSIZE 1024 /* hash buckets for address lookup during hostfile read */
|
|
||||||
#define MAX_PROCS 20 /* max no children for TCP requests */
|
#define MAX_PROCS 20 /* max no children for TCP requests */
|
||||||
#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
|
#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
|
||||||
#define EDNS_PKTSZ 4096 /* default max EDNS.0 UDP packet from RFC5625 */
|
#define EDNS_PKTSZ 4096 /* default max EDNS.0 UDP packet from RFC5625 */
|
||||||
|
#define KEYBLOCK_LEN 140 /* choose to mininise fragmentation when storing DNSSEC keys */
|
||||||
#define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
|
#define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
|
||||||
#define FORWARD_TEST 50 /* try all servers every 50 queries */
|
#define FORWARD_TEST 50 /* try all servers every 50 queries */
|
||||||
#define FORWARD_TIME 20 /* or 20 seconds */
|
#define FORWARD_TIME 20 /* or 20 seconds */
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
#define SMALLDNAME 40 /* most domain names are smaller than this */
|
#define SMALLDNAME 40 /* most domain names are smaller than this */
|
||||||
#define HOSTSFILE "/etc/hosts"
|
#define HOSTSFILE "/etc/hosts"
|
||||||
#define ETHERSFILE "/etc/ethers"
|
#define ETHERSFILE "/etc/ethers"
|
||||||
#define RUNFILE "/var/run/dnsmasq.pid"
|
|
||||||
#define DEFLEASE 3600 /* default lease time, 1 hour */
|
#define DEFLEASE 3600 /* default lease time, 1 hour */
|
||||||
#define CHUSER "nobody"
|
#define CHUSER "nobody"
|
||||||
#define CHGRP "dip"
|
#define CHGRP "dip"
|
||||||
@@ -41,9 +40,13 @@
|
|||||||
#define LOG_MAX 5 /* log-queue length */
|
#define LOG_MAX 5 /* log-queue length */
|
||||||
#define RANDFILE "/dev/urandom"
|
#define RANDFILE "/dev/urandom"
|
||||||
#define EDNS0_OPTION_MAC 5 /* dyndns.org temporary assignment */
|
#define EDNS0_OPTION_MAC 5 /* dyndns.org temporary assignment */
|
||||||
#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* DBUS interface specifics */
|
#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
|
||||||
#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
|
#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
|
||||||
|
#define AUTH_TTL 600 /* default TTL for auth DNS */
|
||||||
|
#define SOA_REFRESH 1200 /* SOA refresh default */
|
||||||
|
#define SOA_RETRY 180 /* SOA retry default */
|
||||||
|
#define SOA_EXPIRY 1209600 /* SOA expiry default */
|
||||||
|
|
||||||
/* compile-time options: uncomment below to enable or do eg.
|
/* compile-time options: uncomment below to enable or do eg.
|
||||||
make COPTS=-DHAVE_BROKEN_RTC
|
make COPTS=-DHAVE_BROKEN_RTC
|
||||||
|
|
||||||
@@ -93,12 +96,18 @@ HAVE_CONNTRACK
|
|||||||
a build-dependency on libnetfilter_conntrack, but the resulting binary will
|
a build-dependency on libnetfilter_conntrack, but the resulting binary will
|
||||||
still run happily on a kernel without conntrack support.
|
still run happily on a kernel without conntrack support.
|
||||||
|
|
||||||
|
HAVE_AUTH
|
||||||
|
define this to include the facility to act as an authoritative DNS
|
||||||
|
server for one or more zones.
|
||||||
|
|
||||||
|
|
||||||
NO_IPV6
|
NO_IPV6
|
||||||
NO_TFTP
|
NO_TFTP
|
||||||
NO_DHCP
|
NO_DHCP
|
||||||
NO_DHCP6
|
NO_DHCP6
|
||||||
NO_SCRIPT
|
NO_SCRIPT
|
||||||
NO_LARGEFILE
|
NO_LARGEFILE
|
||||||
|
NO_AUTH
|
||||||
these are avilable to explictly disable compile time options which would
|
these are avilable to explictly disable compile time options which would
|
||||||
otherwise be enabled automatically (HAVE_IPV6, >2Gb file sizes) or
|
otherwise be enabled automatically (HAVE_IPV6, >2Gb file sizes) or
|
||||||
which are enabled by default in the distributed source tree. Building dnsmasq
|
which are enabled by default in the distributed source tree. Building dnsmasq
|
||||||
@@ -117,9 +126,10 @@ RESOLVFILE
|
|||||||
has no library dependencies other than libc */
|
has no library dependencies other than libc */
|
||||||
|
|
||||||
#define HAVE_DHCP
|
#define HAVE_DHCP
|
||||||
/* #define HAVE_DHCP6 */
|
#define HAVE_DHCP6
|
||||||
#define HAVE_TFTP
|
#define HAVE_TFTP
|
||||||
#define HAVE_SCRIPT
|
#define HAVE_SCRIPT
|
||||||
|
#define HAVE_AUTH
|
||||||
/* #define HAVE_LUASCRIPT */
|
/* #define HAVE_LUASCRIPT */
|
||||||
/* #define HAVE_BROKEN_RTC */
|
/* #define HAVE_BROKEN_RTC */
|
||||||
/* #define HAVE_DBUS */
|
/* #define HAVE_DBUS */
|
||||||
@@ -158,7 +168,13 @@ RESOLVFILE
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef RUNFILE
|
||||||
|
# if defined(__ANDROID__)
|
||||||
|
# define RUNFILE "/data/dnsmasq.pid"
|
||||||
|
# else
|
||||||
|
# define RUNFILE "/var/run/dnsmasq.pid"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* platform dependent options: these are determined automatically below
|
/* platform dependent options: these are determined automatically below
|
||||||
|
|
||||||
@@ -168,7 +184,7 @@ HAVE_SOLARIS_NETWORK
|
|||||||
define exactly one of these to alter interaction with kernel networking.
|
define exactly one of these to alter interaction with kernel networking.
|
||||||
|
|
||||||
HAVE_GETOPT_LONG
|
HAVE_GETOPT_LONG
|
||||||
defined when GNU-sty;e getopt_long available.
|
defined when GNU-style getopt_long available.
|
||||||
|
|
||||||
HAVE_ARC4RANDOM
|
HAVE_ARC4RANDOM
|
||||||
defined if arc4random() available to get better security from DNS spoofs
|
defined if arc4random() available to get better security from DNS spoofs
|
||||||
@@ -302,6 +318,9 @@ HAVE_SOCKADDR_SA_LEN
|
|||||||
#define HAVE_SCRIPT
|
#define HAVE_SCRIPT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef NO_AUTH
|
||||||
|
#undef HAVE_AUTH
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define a string indicating which options are in use.
|
/* Define a string indicating which options are in use.
|
||||||
DNSMASQP_COMPILE_OPTS is only defined in dnsmasq.c */
|
DNSMASQP_COMPILE_OPTS is only defined in dnsmasq.c */
|
||||||
@@ -360,7 +379,11 @@ static char *compile_opts =
|
|||||||
#ifndef HAVE_CONNTRACK
|
#ifndef HAVE_CONNTRACK
|
||||||
"no-"
|
"no-"
|
||||||
#endif
|
#endif
|
||||||
"conntrack";
|
"conntrack "
|
||||||
|
#ifndef HAVE_AUTH
|
||||||
|
"no-"
|
||||||
|
#endif
|
||||||
|
"auth";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+342
-103
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
|
|
||||||
const char* introspection_xml =
|
const char* introspection_xml_template =
|
||||||
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
|
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
|
||||||
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
|
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
|
||||||
"<node name=\"" DNSMASQ_PATH "\">\n"
|
"<node name=\"" DNSMASQ_PATH "\">\n"
|
||||||
@@ -29,7 +29,7 @@ const char* introspection_xml =
|
|||||||
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
|
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
|
||||||
" </method>\n"
|
" </method>\n"
|
||||||
" </interface>\n"
|
" </interface>\n"
|
||||||
" <interface name=\"" DNSMASQ_SERVICE "\">\n"
|
" <interface name=\"%s\">\n"
|
||||||
" <method name=\"ClearCache\">\n"
|
" <method name=\"ClearCache\">\n"
|
||||||
" </method>\n"
|
" </method>\n"
|
||||||
" <method name=\"GetVersion\">\n"
|
" <method name=\"GetVersion\">\n"
|
||||||
@@ -38,6 +38,12 @@ const char* introspection_xml =
|
|||||||
" <method name=\"SetServers\">\n"
|
" <method name=\"SetServers\">\n"
|
||||||
" <arg name=\"servers\" direction=\"in\" type=\"av\"/>\n"
|
" <arg name=\"servers\" direction=\"in\" type=\"av\"/>\n"
|
||||||
" </method>\n"
|
" </method>\n"
|
||||||
|
" <method name=\"SetDomainServers\">\n"
|
||||||
|
" <arg name=\"servers\" direction=\"in\" type=\"as\"/>\n"
|
||||||
|
" </method>\n"
|
||||||
|
" <method name=\"SetServersEx\">\n"
|
||||||
|
" <arg name=\"servers\" direction=\"in\" type=\"aas\"/>\n"
|
||||||
|
" </method>\n"
|
||||||
" <signal name=\"DhcpLeaseAdded\">\n"
|
" <signal name=\"DhcpLeaseAdded\">\n"
|
||||||
" <arg name=\"ipaddr\" type=\"s\"/>\n"
|
" <arg name=\"ipaddr\" type=\"s\"/>\n"
|
||||||
" <arg name=\"hwaddr\" type=\"s\"/>\n"
|
" <arg name=\"hwaddr\" type=\"s\"/>\n"
|
||||||
@@ -56,6 +62,8 @@ const char* introspection_xml =
|
|||||||
" </interface>\n"
|
" </interface>\n"
|
||||||
"</node>\n";
|
"</node>\n";
|
||||||
|
|
||||||
|
static char *introspection_xml = NULL;
|
||||||
|
|
||||||
struct watch {
|
struct watch {
|
||||||
DBusWatch *watch;
|
DBusWatch *watch;
|
||||||
struct watch *next;
|
struct watch *next;
|
||||||
@@ -97,20 +105,118 @@ static void remove_watch(DBusWatch *watch, void *data)
|
|||||||
w = data; /* no warning */
|
w = data; /* no warning */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dbus_read_servers(DBusMessage *message)
|
static void add_update_server(union mysockaddr *addr,
|
||||||
|
union mysockaddr *source_addr,
|
||||||
|
const char *interface,
|
||||||
|
const char *domain)
|
||||||
|
{
|
||||||
|
struct server *serv;
|
||||||
|
|
||||||
|
/* See if there is a suitable candidate, and unmark */
|
||||||
|
for (serv = daemon->servers; serv; serv = serv->next)
|
||||||
|
if ((serv->flags & SERV_FROM_DBUS) &&
|
||||||
|
(serv->flags & SERV_MARK))
|
||||||
|
{
|
||||||
|
if (domain)
|
||||||
|
{
|
||||||
|
if (!(serv->flags & SERV_HAS_DOMAIN) || !hostname_isequal(domain, serv->domain))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (serv->flags & SERV_HAS_DOMAIN)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
serv->flags &= ~SERV_MARK;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serv && (serv = whine_malloc(sizeof (struct server))))
|
||||||
|
{
|
||||||
|
/* Not found, create a new one. */
|
||||||
|
memset(serv, 0, sizeof(struct server));
|
||||||
|
|
||||||
|
if (domain && !(serv->domain = whine_malloc(strlen(domain)+1)))
|
||||||
|
{
|
||||||
|
free(serv);
|
||||||
|
serv = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serv->next = daemon->servers;
|
||||||
|
daemon->servers = serv;
|
||||||
|
serv->flags = SERV_FROM_DBUS;
|
||||||
|
if (domain)
|
||||||
|
{
|
||||||
|
strcpy(serv->domain, domain);
|
||||||
|
serv->flags |= SERV_HAS_DOMAIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serv)
|
||||||
|
{
|
||||||
|
if (interface)
|
||||||
|
strcpy(serv->interface, interface);
|
||||||
|
else
|
||||||
|
serv->interface[0] = 0;
|
||||||
|
|
||||||
|
if (source_addr->in.sin_family == AF_INET &&
|
||||||
|
addr->in.sin_addr.s_addr == 0 &&
|
||||||
|
serv->domain)
|
||||||
|
serv->flags |= SERV_NO_ADDR;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serv->flags &= ~SERV_NO_ADDR;
|
||||||
|
serv->addr = *addr;
|
||||||
|
serv->source_addr = *source_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mark_dbus(void)
|
||||||
|
{
|
||||||
|
struct server *serv;
|
||||||
|
|
||||||
|
/* mark everything from DBUS */
|
||||||
|
for (serv = daemon->servers; serv; serv = serv->next)
|
||||||
|
if (serv->flags & SERV_FROM_DBUS)
|
||||||
|
serv->flags |= SERV_MARK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup_dbus()
|
||||||
{
|
{
|
||||||
struct server *serv, *tmp, **up;
|
struct server *serv, *tmp, **up;
|
||||||
|
|
||||||
|
/* unlink and free anything still marked. */
|
||||||
|
for (serv = daemon->servers, up = &daemon->servers; serv; serv = tmp)
|
||||||
|
{
|
||||||
|
tmp = serv->next;
|
||||||
|
if (serv->flags & SERV_MARK)
|
||||||
|
{
|
||||||
|
server_gone(serv);
|
||||||
|
*up = serv->next;
|
||||||
|
if (serv->domain)
|
||||||
|
free(serv->domain);
|
||||||
|
free(serv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
up = &serv->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dbus_read_servers(DBusMessage *message)
|
||||||
|
{
|
||||||
DBusMessageIter iter;
|
DBusMessageIter iter;
|
||||||
union mysockaddr addr, source_addr;
|
union mysockaddr addr, source_addr;
|
||||||
char *domain;
|
char *domain;
|
||||||
|
|
||||||
dbus_message_iter_init(message, &iter);
|
dbus_message_iter_init(message, &iter);
|
||||||
|
|
||||||
/* mark everything from DBUS */
|
mark_dbus();
|
||||||
for (serv = daemon->servers; serv; serv = serv->next)
|
|
||||||
if (serv->flags & SERV_FROM_DBUS)
|
|
||||||
serv->flags |= SERV_MARK;
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
@@ -169,6 +275,7 @@ static void dbus_read_servers(DBusMessage *message)
|
|||||||
/* At the end */
|
/* At the end */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* process each domain */
|
||||||
do {
|
do {
|
||||||
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
|
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
|
||||||
{
|
{
|
||||||
@@ -179,83 +286,183 @@ static void dbus_read_servers(DBusMessage *message)
|
|||||||
domain = NULL;
|
domain = NULL;
|
||||||
|
|
||||||
if (!skip)
|
if (!skip)
|
||||||
{
|
add_update_server(&addr, &source_addr, NULL, domain);
|
||||||
/* See if this is already there, and unmark */
|
|
||||||
for (serv = daemon->servers; serv; serv = serv->next)
|
} while (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING);
|
||||||
if ((serv->flags & SERV_FROM_DBUS) &&
|
|
||||||
(serv->flags & SERV_MARK))
|
|
||||||
{
|
|
||||||
if (!(serv->flags & SERV_HAS_DOMAIN) && !domain)
|
|
||||||
{
|
|
||||||
serv->flags &= ~SERV_MARK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((serv->flags & SERV_HAS_DOMAIN) &&
|
|
||||||
domain &&
|
|
||||||
hostname_isequal(domain, serv->domain))
|
|
||||||
{
|
|
||||||
serv->flags &= ~SERV_MARK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!serv && (serv = whine_malloc(sizeof (struct server))))
|
|
||||||
{
|
|
||||||
/* Not found, create a new one. */
|
|
||||||
memset(serv, 0, sizeof(struct server));
|
|
||||||
|
|
||||||
if (domain)
|
|
||||||
serv->domain = whine_malloc(strlen(domain)+1);
|
|
||||||
|
|
||||||
if (domain && !serv->domain)
|
|
||||||
{
|
|
||||||
free(serv);
|
|
||||||
serv = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serv->next = daemon->servers;
|
|
||||||
daemon->servers = serv;
|
|
||||||
serv->flags = SERV_FROM_DBUS;
|
|
||||||
if (domain)
|
|
||||||
{
|
|
||||||
strcpy(serv->domain, domain);
|
|
||||||
serv->flags |= SERV_HAS_DOMAIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serv)
|
|
||||||
{
|
|
||||||
if (source_addr.in.sin_family == AF_INET &&
|
|
||||||
addr.in.sin_addr.s_addr == 0 &&
|
|
||||||
serv->domain)
|
|
||||||
serv->flags |= SERV_NO_ADDR;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
serv->flags &= ~SERV_NO_ADDR;
|
|
||||||
serv->addr = addr;
|
|
||||||
serv->source_addr = source_addr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unlink and free anything still marked. */
|
/* unlink and free anything still marked. */
|
||||||
for (serv = daemon->servers, up = &daemon->servers; serv; serv = tmp)
|
cleanup_dbus();
|
||||||
|
}
|
||||||
|
|
||||||
|
static DBusMessage* dbus_read_servers_ex(DBusMessage *message, int strings)
|
||||||
|
{
|
||||||
|
DBusMessageIter iter, array_iter, string_iter;
|
||||||
|
DBusMessage *error = NULL;
|
||||||
|
const char *addr_err;
|
||||||
|
char *dup = NULL;
|
||||||
|
|
||||||
|
my_syslog(LOG_INFO, _("setting upstream servers from DBus"));
|
||||||
|
|
||||||
|
if (!dbus_message_iter_init(message, &iter))
|
||||||
{
|
{
|
||||||
tmp = serv->next;
|
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
if (serv->flags & SERV_MARK)
|
"Failed to initialize dbus message iter");
|
||||||
{
|
|
||||||
server_gone(serv);
|
|
||||||
*up = serv->next;
|
|
||||||
free(serv);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
up = &serv->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check that the message contains an array of arrays */
|
||||||
|
if ((dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) ||
|
||||||
|
(dbus_message_iter_get_element_type(&iter) != (strings ? DBUS_TYPE_STRING : DBUS_TYPE_ARRAY)))
|
||||||
|
{
|
||||||
|
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
strings ? "Expected array of string" : "Expected array of string arrays");
|
||||||
|
}
|
||||||
|
|
||||||
|
mark_dbus();
|
||||||
|
|
||||||
|
/* array_iter points to each "as" element in the outer array */
|
||||||
|
dbus_message_iter_recurse(&iter, &array_iter);
|
||||||
|
while (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID)
|
||||||
|
{
|
||||||
|
const char *str = NULL;
|
||||||
|
union mysockaddr addr, source_addr;
|
||||||
|
char interface[IF_NAMESIZE];
|
||||||
|
char *str_addr, *str_domain = NULL;
|
||||||
|
|
||||||
|
if (strings)
|
||||||
|
{
|
||||||
|
dbus_message_iter_get_basic(&array_iter, &str);
|
||||||
|
if (!str || !strlen (str))
|
||||||
|
{
|
||||||
|
error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Empty string");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dup the string because it gets modified during parsing */
|
||||||
|
if (!(dup = str_domain = whine_malloc(strlen(str)+1)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
strcpy(str_domain, str);
|
||||||
|
|
||||||
|
/* point to address part of old string for error message */
|
||||||
|
if ((str_addr = strrchr(str, '/')))
|
||||||
|
str = str_addr+1;
|
||||||
|
|
||||||
|
if ((str_addr = strrchr(str_domain, '/')))
|
||||||
|
{
|
||||||
|
if (*str_domain != '/' || str_addr == str_domain)
|
||||||
|
{
|
||||||
|
error = dbus_message_new_error_printf(message,
|
||||||
|
DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"No domain terminator '%s'",
|
||||||
|
str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*str_addr++ = 0;
|
||||||
|
str_domain++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str_addr = str_domain;
|
||||||
|
str_domain = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* check the types of the struct and its elements */
|
||||||
|
if ((dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY) ||
|
||||||
|
(dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_STRING))
|
||||||
|
{
|
||||||
|
error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Expected inner array of strings");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* string_iter points to each "s" element in the inner array */
|
||||||
|
dbus_message_iter_recurse(&array_iter, &string_iter);
|
||||||
|
if (dbus_message_iter_get_arg_type(&string_iter) != DBUS_TYPE_STRING)
|
||||||
|
{
|
||||||
|
/* no IP address given */
|
||||||
|
error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Expected IP address");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbus_message_iter_get_basic(&string_iter, &str);
|
||||||
|
if (!str || !strlen (str))
|
||||||
|
{
|
||||||
|
error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Empty IP address");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dup the string because it gets modified during parsing */
|
||||||
|
if (!(dup = str_addr = whine_malloc(strlen(str)+1)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
strcpy(str_addr, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
memset(&source_addr, 0, sizeof(source_addr));
|
||||||
|
memset(&interface, 0, sizeof(interface));
|
||||||
|
|
||||||
|
/* parse the IP address */
|
||||||
|
addr_err = parse_server(str_addr, &addr, &source_addr, (char *) &interface, NULL);
|
||||||
|
|
||||||
|
if (addr_err)
|
||||||
|
{
|
||||||
|
error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Invalid IP address '%s': %s",
|
||||||
|
str, addr_err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strings)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (str_domain)
|
||||||
|
{
|
||||||
|
if ((p = strchr(str_domain, '/')))
|
||||||
|
*p++ = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
p = NULL;
|
||||||
|
|
||||||
|
add_update_server(&addr, &source_addr, interface, str_domain);
|
||||||
|
} while ((str_domain = p));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* jump past the address to the domain list (if any) */
|
||||||
|
dbus_message_iter_next (&string_iter);
|
||||||
|
|
||||||
|
/* parse domains and add each server/domain pair to the list */
|
||||||
|
do {
|
||||||
|
str = NULL;
|
||||||
|
if (dbus_message_iter_get_arg_type(&string_iter) == DBUS_TYPE_STRING)
|
||||||
|
dbus_message_iter_get_basic(&string_iter, &str);
|
||||||
|
dbus_message_iter_next (&string_iter);
|
||||||
|
|
||||||
|
add_update_server(&addr, &source_addr, interface, str);
|
||||||
|
} while (dbus_message_iter_get_arg_type(&string_iter) == DBUS_TYPE_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* jump to next element in outer array */
|
||||||
|
dbus_message_iter_next(&array_iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_dbus();
|
||||||
|
|
||||||
|
if (dup)
|
||||||
|
free(dup);
|
||||||
|
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBusHandlerResult message_handler(DBusConnection *connection,
|
DBusHandlerResult message_handler(DBusConnection *connection,
|
||||||
@@ -263,23 +470,27 @@ DBusHandlerResult message_handler(DBusConnection *connection,
|
|||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
char *method = (char *)dbus_message_get_member(message);
|
char *method = (char *)dbus_message_get_member(message);
|
||||||
|
DBusMessage *reply = NULL;
|
||||||
|
|
||||||
if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
|
if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
|
||||||
{
|
{
|
||||||
DBusMessage *reply = dbus_message_new_method_return(message);
|
/* string length: "%s" provides space for termination zero */
|
||||||
|
if (!introspection_xml &&
|
||||||
dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_xml, DBUS_TYPE_INVALID);
|
(introspection_xml = whine_malloc(strlen(introspection_xml_template) + strlen(daemon->dbus_name))))
|
||||||
dbus_connection_send (connection, reply, NULL);
|
sprintf(introspection_xml, introspection_xml_template, daemon->dbus_name);
|
||||||
dbus_message_unref (reply);
|
|
||||||
|
if (introspection_xml)
|
||||||
|
{
|
||||||
|
reply = dbus_message_new_method_return(message);
|
||||||
|
dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_xml, DBUS_TYPE_INVALID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(method, "GetVersion") == 0)
|
else if (strcmp(method, "GetVersion") == 0)
|
||||||
{
|
{
|
||||||
char *v = VERSION;
|
char *v = VERSION;
|
||||||
DBusMessage *reply = dbus_message_new_method_return(message);
|
reply = dbus_message_new_method_return(message);
|
||||||
|
|
||||||
dbus_message_append_args(reply, DBUS_TYPE_STRING, &v, DBUS_TYPE_INVALID);
|
dbus_message_append_args(reply, DBUS_TYPE_STRING, &v, DBUS_TYPE_INVALID);
|
||||||
dbus_connection_send (connection, reply, NULL);
|
|
||||||
dbus_message_unref (reply);
|
|
||||||
}
|
}
|
||||||
else if (strcmp(method, "SetServers") == 0)
|
else if (strcmp(method, "SetServers") == 0)
|
||||||
{
|
{
|
||||||
@@ -287,6 +498,16 @@ DBusHandlerResult message_handler(DBusConnection *connection,
|
|||||||
dbus_read_servers(message);
|
dbus_read_servers(message);
|
||||||
check_servers();
|
check_servers();
|
||||||
}
|
}
|
||||||
|
else if (strcmp(method, "SetServersEx") == 0)
|
||||||
|
{
|
||||||
|
reply = dbus_read_servers_ex(message, 0);
|
||||||
|
check_servers();
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "SetDomainServers") == 0)
|
||||||
|
{
|
||||||
|
reply = dbus_read_servers_ex(message, 1);
|
||||||
|
check_servers();
|
||||||
|
}
|
||||||
else if (strcmp(method, "ClearCache") == 0)
|
else if (strcmp(method, "ClearCache") == 0)
|
||||||
clear_cache_and_reload(dnsmasq_time());
|
clear_cache_and_reload(dnsmasq_time());
|
||||||
else
|
else
|
||||||
@@ -294,8 +515,17 @@ DBusHandlerResult message_handler(DBusConnection *connection,
|
|||||||
|
|
||||||
method = user_data; /* no warning */
|
method = user_data; /* no warning */
|
||||||
|
|
||||||
|
/* If no reply or no error, return nothing */
|
||||||
|
if (!reply)
|
||||||
|
reply = dbus_message_new_method_return(message);
|
||||||
|
|
||||||
|
if (reply)
|
||||||
|
{
|
||||||
|
dbus_connection_send (connection, reply, NULL);
|
||||||
|
dbus_message_unref (reply);
|
||||||
|
}
|
||||||
|
|
||||||
return (DBUS_HANDLER_RESULT_HANDLED);
|
return (DBUS_HANDLER_RESULT_HANDLED);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -315,7 +545,7 @@ char *dbus_init(void)
|
|||||||
dbus_connection_set_watch_functions(connection, add_watch, remove_watch,
|
dbus_connection_set_watch_functions(connection, add_watch, remove_watch,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
dbus_error_init (&dbus_error);
|
dbus_error_init (&dbus_error);
|
||||||
dbus_bus_request_name (connection, DNSMASQ_SERVICE, 0, &dbus_error);
|
dbus_bus_request_name (connection, daemon->dbus_name, 0, &dbus_error);
|
||||||
if (dbus_error_is_set (&dbus_error))
|
if (dbus_error_is_set (&dbus_error))
|
||||||
return (char *)dbus_error.message;
|
return (char *)dbus_error.message;
|
||||||
|
|
||||||
@@ -325,7 +555,7 @@ char *dbus_init(void)
|
|||||||
|
|
||||||
daemon->dbus = connection;
|
daemon->dbus = connection;
|
||||||
|
|
||||||
if ((message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, "Up")))
|
if ((message = dbus_message_new_signal(DNSMASQ_PATH, daemon->dbus_name, "Up")))
|
||||||
{
|
{
|
||||||
dbus_connection_send(connection, message, NULL);
|
dbus_connection_send(connection, message, NULL);
|
||||||
dbus_message_unref(message);
|
dbus_message_unref(message);
|
||||||
@@ -396,7 +626,7 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname)
|
|||||||
DBusConnection *connection = (DBusConnection *)daemon->dbus;
|
DBusConnection *connection = (DBusConnection *)daemon->dbus;
|
||||||
DBusMessage* message = NULL;
|
DBusMessage* message = NULL;
|
||||||
DBusMessageIter args;
|
DBusMessageIter args;
|
||||||
char *action_str, *addr, *mac = daemon->namebuff;
|
char *action_str, *mac = daemon->namebuff;
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -406,10 +636,21 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname)
|
|||||||
if (!hostname)
|
if (!hostname)
|
||||||
hostname = "";
|
hostname = "";
|
||||||
|
|
||||||
p = extended_hwaddr(lease->hwaddr_type, lease->hwaddr_len,
|
#ifdef HAVE_DHCP6
|
||||||
lease->hwaddr, lease->clid_len, lease->clid, &i);
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
print_mac(mac, p, i);
|
{
|
||||||
|
print_mac(mac, lease->clid, lease->clid_len);
|
||||||
|
inet_ntop(AF_INET6, lease->hwaddr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
p = extended_hwaddr(lease->hwaddr_type, lease->hwaddr_len,
|
||||||
|
lease->hwaddr, lease->clid_len, lease->clid, &i);
|
||||||
|
print_mac(mac, p, i);
|
||||||
|
inet_ntop(AF_INET, &lease->addr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
}
|
||||||
|
|
||||||
if (action == ACTION_DEL)
|
if (action == ACTION_DEL)
|
||||||
action_str = "DhcpLeaseDeleted";
|
action_str = "DhcpLeaseDeleted";
|
||||||
else if (action == ACTION_ADD)
|
else if (action == ACTION_ADD)
|
||||||
@@ -419,14 +660,12 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname)
|
|||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
addr = inet_ntoa(lease->addr);
|
if (!(message = dbus_message_new_signal(DNSMASQ_PATH, daemon->dbus_name, action_str)))
|
||||||
|
|
||||||
if (!(message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, action_str)))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dbus_message_iter_init_append(message, &args);
|
dbus_message_iter_init_append(message, &args);
|
||||||
|
|
||||||
if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &addr) &&
|
if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &daemon->addrbuff) &&
|
||||||
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mac) &&
|
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mac) &&
|
||||||
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &hostname))
|
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &hostname))
|
||||||
dbus_connection_send(connection, message, NULL);
|
dbus_connection_send(connection, message, NULL);
|
||||||
|
|||||||
@@ -0,0 +1,758 @@
|
|||||||
|
/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 dated June, 1991, or
|
||||||
|
(at your option) version 3 dated 29 June, 2007.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP
|
||||||
|
|
||||||
|
void dhcp_common_init(void)
|
||||||
|
{
|
||||||
|
/* These each hold a DHCP option max size 255
|
||||||
|
and get a terminating zero added */
|
||||||
|
daemon->dhcp_buff = safe_malloc(256);
|
||||||
|
daemon->dhcp_buff2 = safe_malloc(256);
|
||||||
|
daemon->dhcp_buff3 = safe_malloc(256);
|
||||||
|
|
||||||
|
/* dhcp_packet is used by v4 and v6, outpacket only by v6
|
||||||
|
sizeof(struct dhcp_packet) is as good an initial size as any,
|
||||||
|
even for v6 */
|
||||||
|
expand_buf(&daemon->dhcp_packet, sizeof(struct dhcp_packet));
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->dhcp6)
|
||||||
|
expand_buf(&daemon->outpacket, sizeof(struct dhcp_packet));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t recv_dhcp_packet(int fd, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
ssize_t sz;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
msg->msg_flags = 0;
|
||||||
|
while ((sz = recvmsg(fd, msg, MSG_PEEK | MSG_TRUNC)) == -1 && errno == EINTR);
|
||||||
|
|
||||||
|
if (sz == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!(msg->msg_flags & MSG_TRUNC))
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Very new Linux kernels return the actual size needed,
|
||||||
|
older ones always return truncated size */
|
||||||
|
if ((size_t)sz == msg->msg_iov->iov_len)
|
||||||
|
{
|
||||||
|
if (!expand_buf(msg->msg_iov, sz + 100))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
expand_buf(msg->msg_iov, sz);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((sz = recvmsg(fd, msg, 0)) == -1 && errno == EINTR);
|
||||||
|
|
||||||
|
return (msg->msg_flags & MSG_TRUNC) ? -1 : sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dhcp_netid *run_tag_if(struct dhcp_netid *tags)
|
||||||
|
{
|
||||||
|
struct tag_if *exprs;
|
||||||
|
struct dhcp_netid_list *list;
|
||||||
|
|
||||||
|
for (exprs = daemon->tag_if; exprs; exprs = exprs->next)
|
||||||
|
if (match_netid(exprs->tag, tags, 1))
|
||||||
|
for (list = exprs->set; list; list = list->next)
|
||||||
|
{
|
||||||
|
list->list->next = tags;
|
||||||
|
tags = list->list;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *context_tags, struct dhcp_opt *opts)
|
||||||
|
{
|
||||||
|
struct dhcp_netid *tagif = run_tag_if(tags);
|
||||||
|
struct dhcp_opt *opt;
|
||||||
|
|
||||||
|
/* flag options which are valid with the current tag set (sans context tags) */
|
||||||
|
for (opt = opts; opt; opt = opt->next)
|
||||||
|
{
|
||||||
|
opt->flags &= ~DHOPT_TAGOK;
|
||||||
|
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) &&
|
||||||
|
match_netid(opt->netid, tagif, 0))
|
||||||
|
opt->flags |= DHOPT_TAGOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now flag options which are valid, including the context tags,
|
||||||
|
otherwise valid options are inhibited if we found a higher priority one above */
|
||||||
|
if (context_tags)
|
||||||
|
{
|
||||||
|
struct dhcp_netid *last_tag;
|
||||||
|
|
||||||
|
for (last_tag = context_tags; last_tag->next; last_tag = last_tag->next);
|
||||||
|
last_tag->next = tags;
|
||||||
|
tagif = run_tag_if(context_tags);
|
||||||
|
|
||||||
|
/* reset stuff with tag:!<tag> which now matches. */
|
||||||
|
for (opt = opts; opt; opt = opt->next)
|
||||||
|
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) &&
|
||||||
|
(opt->flags & DHOPT_TAGOK) &&
|
||||||
|
!match_netid(opt->netid, tagif, 0))
|
||||||
|
opt->flags &= ~DHOPT_TAGOK;
|
||||||
|
|
||||||
|
for (opt = opts; opt; opt = opt->next)
|
||||||
|
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925 | DHOPT_TAGOK)) &&
|
||||||
|
match_netid(opt->netid, tagif, 0))
|
||||||
|
{
|
||||||
|
struct dhcp_opt *tmp;
|
||||||
|
for (tmp = opts; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->opt == opt->opt && opt->netid && (tmp->flags & DHOPT_TAGOK))
|
||||||
|
break;
|
||||||
|
if (!tmp)
|
||||||
|
opt->flags |= DHOPT_TAGOK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now flag untagged options which are not overridden by tagged ones */
|
||||||
|
for (opt = opts; opt; opt = opt->next)
|
||||||
|
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925 | DHOPT_TAGOK)) && !opt->netid)
|
||||||
|
{
|
||||||
|
struct dhcp_opt *tmp;
|
||||||
|
for (tmp = opts; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->opt == opt->opt && (tmp->flags & DHOPT_TAGOK))
|
||||||
|
break;
|
||||||
|
if (!tmp)
|
||||||
|
opt->flags |= DHOPT_TAGOK;
|
||||||
|
else if (!tmp->netid)
|
||||||
|
my_syslog(MS_DHCP | LOG_WARNING, _("Ignoring duplicate dhcp-option %d"), tmp->opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is every member of check matched by a member of pool?
|
||||||
|
If tagnotneeded, untagged is OK */
|
||||||
|
int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int tagnotneeded)
|
||||||
|
{
|
||||||
|
struct dhcp_netid *tmp1;
|
||||||
|
|
||||||
|
if (!check && !tagnotneeded)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (; check; check = check->next)
|
||||||
|
{
|
||||||
|
/* '#' for not is for backwards compat. */
|
||||||
|
if (check->net[0] != '!' && check->net[0] != '#')
|
||||||
|
{
|
||||||
|
for (tmp1 = pool; tmp1; tmp1 = tmp1->next)
|
||||||
|
if (strcmp(check->net, tmp1->net) == 0)
|
||||||
|
break;
|
||||||
|
if (!tmp1)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (tmp1 = pool; tmp1; tmp1 = tmp1->next)
|
||||||
|
if (strcmp((check->net)+1, tmp1->net) == 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* return domain or NULL if none. */
|
||||||
|
char *strip_hostname(char *hostname)
|
||||||
|
{
|
||||||
|
char *dot = strchr(hostname, '.');
|
||||||
|
|
||||||
|
if (!dot)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
*dot = 0; /* truncate */
|
||||||
|
if (strlen(dot+1) != 0)
|
||||||
|
return dot+1;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_tags(struct dhcp_netid *netid, u32 xid)
|
||||||
|
{
|
||||||
|
if (netid && option_bool(OPT_LOG_OPTS))
|
||||||
|
{
|
||||||
|
char *s = daemon->namebuff;
|
||||||
|
for (*s = 0; netid; netid = netid->next)
|
||||||
|
{
|
||||||
|
/* kill dupes. */
|
||||||
|
struct dhcp_netid *n;
|
||||||
|
|
||||||
|
for (n = netid->next; n; n = n->next)
|
||||||
|
if (strcmp(netid->net, n->net) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!n)
|
||||||
|
{
|
||||||
|
strncat (s, netid->net, (MAXDNAME-1) - strlen(s));
|
||||||
|
if (netid->next)
|
||||||
|
strncat (s, ", ", (MAXDNAME-1) - strlen(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, _("%u tags: %s"), xid, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int match_bytes(struct dhcp_opt *o, unsigned char *p, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (o->len > len)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (o->len == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (o->flags & DHOPT_HEX)
|
||||||
|
{
|
||||||
|
if (memcmp_masked(o->val, p, o->len, o->u.wildcard_mask))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (i = 0; i <= (len - o->len); )
|
||||||
|
{
|
||||||
|
if (memcmp(o->val, p + i, o->len) == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (o->flags & DHOPT_STRING)
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
i += o->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dhcp_update_configs(struct dhcp_config *configs)
|
||||||
|
{
|
||||||
|
/* Some people like to keep all static IP addresses in /etc/hosts.
|
||||||
|
This goes through /etc/hosts and sets static addresses for any DHCP config
|
||||||
|
records which don't have an address and whose name matches.
|
||||||
|
We take care to maintain the invariant that any IP address can appear
|
||||||
|
in at most one dhcp-host. Since /etc/hosts can be re-read by SIGHUP,
|
||||||
|
restore the status-quo ante first. */
|
||||||
|
|
||||||
|
struct dhcp_config *config, *conf_tmp;
|
||||||
|
struct crec *crec;
|
||||||
|
int prot = AF_INET;
|
||||||
|
|
||||||
|
for (config = configs; config; config = config->next)
|
||||||
|
if (config->flags & CONFIG_ADDR_HOSTS)
|
||||||
|
config->flags &= ~(CONFIG_ADDR | CONFIG_ADDR6 | CONFIG_ADDR_HOSTS);
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
again:
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (daemon->port != 0)
|
||||||
|
for (config = configs; config; config = config->next)
|
||||||
|
{
|
||||||
|
int conflags = CONFIG_ADDR;
|
||||||
|
int cacheflags = F_IPV4;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET6)
|
||||||
|
{
|
||||||
|
conflags = CONFIG_ADDR6;
|
||||||
|
cacheflags = F_IPV6;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!(config->flags & conflags) &&
|
||||||
|
(config->flags & CONFIG_NAME) &&
|
||||||
|
(crec = cache_find_by_name(NULL, config->hostname, 0, cacheflags)) &&
|
||||||
|
(crec->flags & F_HOSTS))
|
||||||
|
{
|
||||||
|
if (cache_find_by_name(crec, config->hostname, 0, cacheflags))
|
||||||
|
{
|
||||||
|
/* use primary (first) address */
|
||||||
|
while (crec && !(crec->flags & F_REVERSE))
|
||||||
|
crec = cache_find_by_name(crec, config->hostname, 0, cacheflags);
|
||||||
|
if (!crec)
|
||||||
|
continue; /* should be never */
|
||||||
|
inet_ntop(prot, &crec->addr.addr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
my_syslog(MS_DHCP | LOG_WARNING, _("%s has more than one address in hostsfile, using %s for DHCP"),
|
||||||
|
config->hostname, daemon->addrbuff);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prot == AF_INET &&
|
||||||
|
(!(conf_tmp = config_find_by_address(configs, crec->addr.addr.addr.addr4)) || conf_tmp == config))
|
||||||
|
{
|
||||||
|
config->addr = crec->addr.addr.addr.addr4;
|
||||||
|
config->flags |= CONFIG_ADDR | CONFIG_ADDR_HOSTS;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET6 &&
|
||||||
|
(!(conf_tmp = config_find_by_address6(configs, &crec->addr.addr.addr.addr6, 128, 0)) || conf_tmp == config))
|
||||||
|
{
|
||||||
|
memcpy(&config->addr6, &crec->addr.addr.addr.addr6, IN6ADDRSZ);
|
||||||
|
config->flags |= CONFIG_ADDR6 | CONFIG_ADDR_HOSTS;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inet_ntop(prot, &crec->addr.addr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
my_syslog(MS_DHCP | LOG_WARNING, _("duplicate IP address %s (%s) in dhcp-config directive"),
|
||||||
|
daemon->addrbuff, config->hostname);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET)
|
||||||
|
{
|
||||||
|
prot = AF_INET6;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
|
void bindtodevice(int fd)
|
||||||
|
{
|
||||||
|
/* If we are doing DHCP on exactly one interface, and running linux, do SO_BINDTODEVICE
|
||||||
|
to that device. This is for the use case of (eg) OpenStack, which runs a new
|
||||||
|
dnsmasq instance for each VLAN interface it creates. Without the BINDTODEVICE,
|
||||||
|
individual processes don't always see the packets they should.
|
||||||
|
SO_BINDTODEVICE is only available Linux. */
|
||||||
|
|
||||||
|
struct irec *iface, *found;
|
||||||
|
|
||||||
|
for (found = NULL, iface = daemon->interfaces; iface; iface = iface->next)
|
||||||
|
if (iface->dhcp_ok)
|
||||||
|
{
|
||||||
|
if (!found)
|
||||||
|
found = iface;
|
||||||
|
else if (strcmp(found->name, iface->name) != 0)
|
||||||
|
{
|
||||||
|
/* more than one. */
|
||||||
|
found = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
struct ifreq ifr;
|
||||||
|
strcpy(ifr.ifr_name, found->name);
|
||||||
|
/* only allowed by root. */
|
||||||
|
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) == -1 &&
|
||||||
|
errno != EPERM)
|
||||||
|
die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, EC_BADNET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const struct opttab_t {
|
||||||
|
char *name;
|
||||||
|
u16 val, size;
|
||||||
|
} opttab[] = {
|
||||||
|
{ "netmask", 1, OT_ADDR_LIST },
|
||||||
|
{ "time-offset", 2, 4 },
|
||||||
|
{ "router", 3, OT_ADDR_LIST },
|
||||||
|
{ "dns-server", 6, OT_ADDR_LIST },
|
||||||
|
{ "log-server", 7, OT_ADDR_LIST },
|
||||||
|
{ "lpr-server", 9, OT_ADDR_LIST },
|
||||||
|
{ "hostname", 12, OT_INTERNAL | OT_NAME },
|
||||||
|
{ "boot-file-size", 13, 2 | OT_DEC },
|
||||||
|
{ "domain-name", 15, OT_NAME },
|
||||||
|
{ "swap-server", 16, OT_ADDR_LIST },
|
||||||
|
{ "root-path", 17, OT_NAME },
|
||||||
|
{ "extension-path", 18, OT_NAME },
|
||||||
|
{ "ip-forward-enable", 19, 1 },
|
||||||
|
{ "non-local-source-routing", 20, 1 },
|
||||||
|
{ "policy-filter", 21, OT_ADDR_LIST },
|
||||||
|
{ "max-datagram-reassembly", 22, 2 | OT_DEC },
|
||||||
|
{ "default-ttl", 23, 1 | OT_DEC },
|
||||||
|
{ "mtu", 26, 2 | OT_DEC },
|
||||||
|
{ "all-subnets-local", 27, 1 },
|
||||||
|
{ "broadcast", 28, OT_INTERNAL | OT_ADDR_LIST },
|
||||||
|
{ "router-discovery", 31, 1 },
|
||||||
|
{ "router-solicitation", 32, OT_ADDR_LIST },
|
||||||
|
{ "static-route", 33, OT_ADDR_LIST },
|
||||||
|
{ "trailer-encapsulation", 34, 1 },
|
||||||
|
{ "arp-timeout", 35, 4 | OT_DEC },
|
||||||
|
{ "ethernet-encap", 36, 1 },
|
||||||
|
{ "tcp-ttl", 37, 1 },
|
||||||
|
{ "tcp-keepalive", 38, 4 | OT_DEC },
|
||||||
|
{ "nis-domain", 40, OT_NAME },
|
||||||
|
{ "nis-server", 41, OT_ADDR_LIST },
|
||||||
|
{ "ntp-server", 42, OT_ADDR_LIST },
|
||||||
|
{ "vendor-encap", 43, OT_INTERNAL },
|
||||||
|
{ "netbios-ns", 44, OT_ADDR_LIST },
|
||||||
|
{ "netbios-dd", 45, OT_ADDR_LIST },
|
||||||
|
{ "netbios-nodetype", 46, 1 },
|
||||||
|
{ "netbios-scope", 47, 0 },
|
||||||
|
{ "x-windows-fs", 48, OT_ADDR_LIST },
|
||||||
|
{ "x-windows-dm", 49, OT_ADDR_LIST },
|
||||||
|
{ "requested-address", 50, OT_INTERNAL | OT_ADDR_LIST },
|
||||||
|
{ "lease-time", 51, OT_INTERNAL | OT_TIME },
|
||||||
|
{ "option-overload", 52, OT_INTERNAL },
|
||||||
|
{ "message-type", 53, OT_INTERNAL | OT_DEC },
|
||||||
|
{ "server-identifier", 54, OT_INTERNAL | OT_ADDR_LIST },
|
||||||
|
{ "parameter-request", 55, OT_INTERNAL },
|
||||||
|
{ "message", 56, OT_INTERNAL },
|
||||||
|
{ "max-message-size", 57, OT_INTERNAL },
|
||||||
|
{ "T1", 58, OT_INTERNAL | OT_TIME},
|
||||||
|
{ "T2", 59, OT_INTERNAL | OT_TIME},
|
||||||
|
{ "vendor-class", 60, 0 },
|
||||||
|
{ "client-id", 61, OT_INTERNAL },
|
||||||
|
{ "nis+-domain", 64, OT_NAME },
|
||||||
|
{ "nis+-server", 65, OT_ADDR_LIST },
|
||||||
|
{ "tftp-server", 66, OT_NAME },
|
||||||
|
{ "bootfile-name", 67, OT_NAME },
|
||||||
|
{ "mobile-ip-home", 68, OT_ADDR_LIST },
|
||||||
|
{ "smtp-server", 69, OT_ADDR_LIST },
|
||||||
|
{ "pop3-server", 70, OT_ADDR_LIST },
|
||||||
|
{ "nntp-server", 71, OT_ADDR_LIST },
|
||||||
|
{ "irc-server", 74, OT_ADDR_LIST },
|
||||||
|
{ "user-class", 77, 0 },
|
||||||
|
{ "FQDN", 81, OT_INTERNAL },
|
||||||
|
{ "agent-id", 82, OT_INTERNAL },
|
||||||
|
{ "client-arch", 93, 2 | OT_DEC },
|
||||||
|
{ "client-interface-id", 94, 0 },
|
||||||
|
{ "client-machine-id", 97, 0 },
|
||||||
|
{ "subnet-select", 118, OT_INTERNAL },
|
||||||
|
{ "domain-search", 119, OT_RFC1035_NAME },
|
||||||
|
{ "sip-server", 120, 0 },
|
||||||
|
{ "classless-static-route", 121, 0 },
|
||||||
|
{ "vendor-id-encap", 125, 0 },
|
||||||
|
{ "server-ip-address", 255, OT_ADDR_LIST }, /* special, internal only, sets siaddr */
|
||||||
|
{ NULL, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
static const struct opttab_t opttab6[] = {
|
||||||
|
{ "client-id", 1, OT_INTERNAL },
|
||||||
|
{ "server-id", 2, OT_INTERNAL },
|
||||||
|
{ "ia-na", 3, OT_INTERNAL },
|
||||||
|
{ "ia-ta", 4, OT_INTERNAL },
|
||||||
|
{ "iaaddr", 5, OT_INTERNAL },
|
||||||
|
{ "oro", 6, OT_INTERNAL },
|
||||||
|
{ "preference", 7, OT_INTERNAL | OT_DEC },
|
||||||
|
{ "unicast", 12, OT_INTERNAL },
|
||||||
|
{ "status", 13, OT_INTERNAL },
|
||||||
|
{ "rapid-commit", 14, OT_INTERNAL },
|
||||||
|
{ "user-class", 15, OT_INTERNAL | OT_CSTRING },
|
||||||
|
{ "vendor-class", 16, OT_INTERNAL | OT_CSTRING },
|
||||||
|
{ "vendor-opts", 17, OT_INTERNAL },
|
||||||
|
{ "sip-server-domain", 21, OT_RFC1035_NAME },
|
||||||
|
{ "sip-server", 22, OT_ADDR_LIST },
|
||||||
|
{ "dns-server", 23, OT_ADDR_LIST },
|
||||||
|
{ "domain-search", 24, OT_RFC1035_NAME },
|
||||||
|
{ "nis-server", 27, OT_ADDR_LIST },
|
||||||
|
{ "nis+-server", 28, OT_ADDR_LIST },
|
||||||
|
{ "nis-domain", 29, OT_RFC1035_NAME },
|
||||||
|
{ "nis+-domain", 30, OT_RFC1035_NAME },
|
||||||
|
{ "sntp-server", 31, OT_ADDR_LIST },
|
||||||
|
{ "information-refresh-time", 32, OT_TIME },
|
||||||
|
{ "FQDN", 39, OT_INTERNAL | OT_RFC1035_NAME },
|
||||||
|
{ "ntp-server", 56, OT_ADDR_LIST },
|
||||||
|
{ "bootfile-url", 59, OT_NAME },
|
||||||
|
{ "bootfile-param", 60, OT_CSTRING },
|
||||||
|
{ NULL, 0, 0 }
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void display_opts(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf(_("Known DHCP options:\n"));
|
||||||
|
|
||||||
|
for (i = 0; opttab[i].name; i++)
|
||||||
|
if (!(opttab[i].size & OT_INTERNAL))
|
||||||
|
printf("%3d %s\n", opttab[i].val, opttab[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
void display_opts6(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
printf(_("Known DHCPv6 options:\n"));
|
||||||
|
|
||||||
|
for (i = 0; opttab6[i].name; i++)
|
||||||
|
if (!(opttab6[i].size & OT_INTERNAL))
|
||||||
|
printf("%3d %s\n", opttab6[i].val, opttab6[i].name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
u16 lookup_dhcp_opt(int prot, char *name)
|
||||||
|
{
|
||||||
|
const struct opttab_t *t;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET6)
|
||||||
|
t = opttab6;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
t = opttab;
|
||||||
|
|
||||||
|
for (i = 0; t[i].name; i++)
|
||||||
|
if (!(t[i].size & OT_INTERNAL) &&
|
||||||
|
strcasecmp(t[i].name, name) == 0)
|
||||||
|
return t[i].val;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u16 lookup_dhcp_len(int prot, u16 val)
|
||||||
|
{
|
||||||
|
const struct opttab_t *t;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET6)
|
||||||
|
t = opttab6;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
t = opttab;
|
||||||
|
|
||||||
|
for (i = 0; t[i].name; i++)
|
||||||
|
if (val == t[i].val)
|
||||||
|
{
|
||||||
|
if (t[i].size & OT_INTERNAL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return t[i].size & ~OT_DEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *option_string(int prot, unsigned int opt, unsigned char *val, int opt_len, char *buf, int buf_len)
|
||||||
|
{
|
||||||
|
int o, i, j, nodecode = 0;
|
||||||
|
const struct opttab_t *ot = opttab;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET6)
|
||||||
|
ot = opttab6;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (o = 0; ot[o].name; o++)
|
||||||
|
if (ot[o].val == opt)
|
||||||
|
{
|
||||||
|
if (buf)
|
||||||
|
{
|
||||||
|
memset(buf, 0, buf_len);
|
||||||
|
|
||||||
|
if (ot[o].size & OT_ADDR_LIST)
|
||||||
|
{
|
||||||
|
struct all_addr addr;
|
||||||
|
int addr_len = INADDRSZ;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (prot == AF_INET6)
|
||||||
|
addr_len = IN6ADDRSZ;
|
||||||
|
#endif
|
||||||
|
for (buf[0]= 0, i = 0; i <= opt_len - addr_len; i += addr_len)
|
||||||
|
{
|
||||||
|
if (i != 0)
|
||||||
|
strncat(buf, ", ", buf_len - strlen(buf));
|
||||||
|
/* align */
|
||||||
|
memcpy(&addr, &val[i], addr_len);
|
||||||
|
inet_ntop(prot, &val[i], daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
strncat(buf, daemon->addrbuff, buf_len - strlen(buf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ot[o].size & OT_NAME)
|
||||||
|
for (i = 0, j = 0; i < opt_len && j < buf_len ; i++)
|
||||||
|
{
|
||||||
|
char c = val[i];
|
||||||
|
if (isprint((int)c))
|
||||||
|
buf[j++] = c;
|
||||||
|
}
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
/* We don't handle compressed rfc1035 names, so no good in IPv4 land */
|
||||||
|
else if ((ot[o].size & OT_RFC1035_NAME) && prot == AF_INET6)
|
||||||
|
{
|
||||||
|
i = 0, j = 0;
|
||||||
|
while (i < opt_len && val[i] != 0)
|
||||||
|
{
|
||||||
|
int k, l = i + val[i] + 1;
|
||||||
|
for (k = i + 1; k < opt_len && k < l && j < buf_len ; k++)
|
||||||
|
{
|
||||||
|
char c = val[k];
|
||||||
|
if (isprint((int)c))
|
||||||
|
buf[j++] = c;
|
||||||
|
}
|
||||||
|
i = l;
|
||||||
|
if (val[i] != 0 && j < buf_len)
|
||||||
|
buf[j++] = '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((ot[o].size & OT_CSTRING))
|
||||||
|
{
|
||||||
|
int k, len;
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
i = 0, j = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
p = &val[i];
|
||||||
|
GETSHORT(len, p);
|
||||||
|
for (k = 0; k < len && j < buf_len; k++)
|
||||||
|
{
|
||||||
|
char c = *p++;
|
||||||
|
if (isprint((int)c))
|
||||||
|
buf[j++] = c;
|
||||||
|
}
|
||||||
|
i += len +2;
|
||||||
|
if (i >= opt_len)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (j < buf_len)
|
||||||
|
buf[j++] = ',';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else if ((ot[o].size & (OT_DEC | OT_TIME)) && opt_len != 0)
|
||||||
|
{
|
||||||
|
unsigned int dec = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < opt_len; i++)
|
||||||
|
dec = (dec << 8) | val[i];
|
||||||
|
|
||||||
|
if (ot[o].size & OT_TIME)
|
||||||
|
prettyprint_time(buf, dec);
|
||||||
|
else
|
||||||
|
sprintf(buf, "%u", dec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
nodecode = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt_len != 0 && buf && (!ot[o].name || nodecode))
|
||||||
|
{
|
||||||
|
int trunc = 0;
|
||||||
|
if (opt_len > 14)
|
||||||
|
{
|
||||||
|
trunc = 1;
|
||||||
|
opt_len = 14;
|
||||||
|
}
|
||||||
|
print_mac(buf, val, opt_len);
|
||||||
|
if (trunc)
|
||||||
|
strncat(buf, "...", buf_len - strlen(buf));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ot[o].name ? ot[o].name : "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_context(int family, struct dhcp_context *context)
|
||||||
|
{
|
||||||
|
/* Cannot use dhcp_buff* for RA contexts */
|
||||||
|
|
||||||
|
void *start = &context->start;
|
||||||
|
void *end = &context->end;
|
||||||
|
char *n = "", *m = "", *p = daemon->namebuff;
|
||||||
|
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (family == AF_INET6)
|
||||||
|
{
|
||||||
|
struct in6_addr subnet = context->start6;
|
||||||
|
if (!(context->flags & CONTEXT_TEMPLATE))
|
||||||
|
setaddr6part(&subnet, 0);
|
||||||
|
inet_ntop(AF_INET6, &subnet, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
start = &context->start6;
|
||||||
|
end = &context->end6;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((context->flags & CONTEXT_DHCP) ||
|
||||||
|
!(context->flags & (CONTEXT_CONSTRUCTED | CONTEXT_TEMPLATE)))
|
||||||
|
{
|
||||||
|
if (family != AF_INET && (context->flags & CONTEXT_DEPRECATE))
|
||||||
|
strcpy(daemon->namebuff, _(", prefix deprecated"));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p += sprintf(p, _(", lease time "));
|
||||||
|
m = p;
|
||||||
|
prettyprint_time(p, context->lease_time);
|
||||||
|
p += strlen(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (context->flags & CONTEXT_CONSTRUCTED)
|
||||||
|
{
|
||||||
|
n = p;
|
||||||
|
p += sprintf(p, ", constructed for %s", context->template_interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->flags & CONTEXT_TEMPLATE)
|
||||||
|
{
|
||||||
|
n = p;
|
||||||
|
p += sprintf(p, ", template for %s", context->template_interface);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((context->flags & CONTEXT_DHCP) || family == AF_INET)
|
||||||
|
{
|
||||||
|
inet_ntop(family, start, daemon->dhcp_buff, 256);
|
||||||
|
inet_ntop(family, end, daemon->dhcp_buff3, 256);
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO,
|
||||||
|
(context->flags & CONTEXT_RA_STATELESS) ?
|
||||||
|
_("%s stateless on %s%.0s%.0s") :
|
||||||
|
(context->flags & CONTEXT_STATIC) ?
|
||||||
|
_("%s, static leases only on %.0s%s%s") :
|
||||||
|
(context->flags & CONTEXT_PROXY) ?
|
||||||
|
_("%s, proxy on subnet %.0s%s%.0s") :
|
||||||
|
_("%s, IP range %s -- %s%s"),
|
||||||
|
(family != AF_INET) ? "DHCPv6" : "DHCP",
|
||||||
|
daemon->dhcp_buff, daemon->dhcp_buff3, daemon->namebuff);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (context->flags & CONTEXT_RA_NAME)
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, _("DHCPv4-derived IPv6 names on %s%s"),
|
||||||
|
daemon->addrbuff, n);
|
||||||
|
|
||||||
|
|
||||||
|
if (context->flags & CONTEXT_RA)
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, _("router advertisement on %s%s%s"),
|
||||||
|
daemon->addrbuff,
|
||||||
|
(context->flags & (CONTEXT_CONSTRUCTED | CONTEXT_TEMPLATE)) ? "" : ", prefix valid ",
|
||||||
|
(context->flags & (CONTEXT_CONSTRUCTED | CONTEXT_TEMPLATE)) ? n : m);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
File renamed without changes.
+6
-191
@@ -66,7 +66,7 @@ static int make_fd(int port)
|
|||||||
/* When bind-interfaces is set, there might be more than one dnmsasq
|
/* When bind-interfaces is set, there might be more than one dnmsasq
|
||||||
instance binding port 67. That's OK if they serve different networks.
|
instance binding port 67. That's OK if they serve different networks.
|
||||||
Need to set REUSEADDR to make this posible, or REUSEPORT on *BSD. */
|
Need to set REUSEADDR to make this posible, or REUSEPORT on *BSD. */
|
||||||
if (option_bool(OPT_NOWILD))
|
if (option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND))
|
||||||
{
|
{
|
||||||
#ifdef SO_REUSEPORT
|
#ifdef SO_REUSEPORT
|
||||||
int rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &oneopt, sizeof(oneopt));
|
int rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &oneopt, sizeof(oneopt));
|
||||||
@@ -116,46 +116,7 @@ void dhcp_init(void)
|
|||||||
|
|
||||||
/* Make BPF raw send socket */
|
/* Make BPF raw send socket */
|
||||||
init_bpf();
|
init_bpf();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
check_dhcp_hosts(1);
|
|
||||||
|
|
||||||
daemon->dhcp_packet.iov_len = sizeof(struct dhcp_packet);
|
|
||||||
daemon->dhcp_packet.iov_base = safe_malloc(daemon->dhcp_packet.iov_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t recv_dhcp_packet(int fd, struct msghdr *msg)
|
|
||||||
{
|
|
||||||
ssize_t sz;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
msg->msg_flags = 0;
|
|
||||||
while ((sz = recvmsg(fd, msg, MSG_PEEK | MSG_TRUNC)) == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
if (sz == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!(msg->msg_flags & MSG_TRUNC))
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Very new Linux kernels return the actual size needed,
|
|
||||||
older ones always return truncated size */
|
|
||||||
if ((size_t)sz == daemon->dhcp_packet.iov_len)
|
|
||||||
{
|
|
||||||
if (!expand_buf(&daemon->dhcp_packet, sz + 100))
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expand_buf(&daemon->dhcp_packet, sz);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((sz = recvmsg(fd, msg, 0)) == -1 && errno == EINTR);
|
|
||||||
|
|
||||||
return (msg->msg_flags & MSG_TRUNC) ? -1 : sz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dhcp_packet(time_t now, int pxe_fd)
|
void dhcp_packet(time_t now, int pxe_fd)
|
||||||
@@ -294,14 +255,6 @@ void dhcp_packet(time_t now, int pxe_fd)
|
|||||||
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* weird libvirt-inspired access control */
|
|
||||||
for (context = daemon->dhcp; context; context = context->next)
|
|
||||||
if (!context->interface || strcmp(context->interface, ifr.ifr_name) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!context)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* unlinked contexts are marked by context->current == context */
|
/* unlinked contexts are marked by context->current == context */
|
||||||
for (context = daemon->dhcp; context; context = context->next)
|
for (context = daemon->dhcp; context; context = context->next)
|
||||||
context->current = context;
|
context->current = context;
|
||||||
@@ -309,12 +262,12 @@ void dhcp_packet(time_t now, int pxe_fd)
|
|||||||
parm.current = NULL;
|
parm.current = NULL;
|
||||||
parm.ind = iface_index;
|
parm.ind = iface_index;
|
||||||
|
|
||||||
if (!iface_check(AF_INET, (struct all_addr *)&iface_addr, ifr.ifr_name))
|
if (!iface_check(AF_INET, (struct all_addr *)&iface_addr, ifr.ifr_name, NULL))
|
||||||
{
|
{
|
||||||
/* If we failed to match the primary address of the interface, see if we've got a --listen-address
|
/* If we failed to match the primary address of the interface, see if we've got a --listen-address
|
||||||
for a secondary */
|
for a secondary */
|
||||||
struct match_param match;
|
struct match_param match;
|
||||||
|
|
||||||
match.matched = 0;
|
match.matched = 0;
|
||||||
match.ind = iface_index;
|
match.ind = iface_index;
|
||||||
|
|
||||||
@@ -336,7 +289,7 @@ void dhcp_packet(time_t now, int pxe_fd)
|
|||||||
iov.iov_len = dhcp_reply(parm.current, ifr.ifr_name, iface_index, (size_t)sz,
|
iov.iov_len = dhcp_reply(parm.current, ifr.ifr_name, iface_index, (size_t)sz,
|
||||||
now, unicast_dest, &is_inform, pxe_fd, iface_addr);
|
now, unicast_dest, &is_inform, pxe_fd, iface_addr);
|
||||||
lease_update_file(now);
|
lease_update_file(now);
|
||||||
lease_update_dns();
|
lease_update_dns(0);
|
||||||
|
|
||||||
if (iov.iov_len == 0)
|
if (iov.iov_len == 0)
|
||||||
return;
|
return;
|
||||||
@@ -611,50 +564,6 @@ struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct i
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is every member of check matched by a member of pool?
|
|
||||||
If tagnotneeded, untagged is OK */
|
|
||||||
int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int tagnotneeded)
|
|
||||||
{
|
|
||||||
struct dhcp_netid *tmp1;
|
|
||||||
|
|
||||||
if (!check && !tagnotneeded)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (; check; check = check->next)
|
|
||||||
{
|
|
||||||
/* '#' for not is for backwards compat. */
|
|
||||||
if (check->net[0] != '!' && check->net[0] != '#')
|
|
||||||
{
|
|
||||||
for (tmp1 = pool; tmp1; tmp1 = tmp1->next)
|
|
||||||
if (strcmp(check->net, tmp1->net) == 0)
|
|
||||||
break;
|
|
||||||
if (!tmp1)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (tmp1 = pool; tmp1; tmp1 = tmp1->next)
|
|
||||||
if (strcmp((check->net)+1, tmp1->net) == 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct dhcp_netid *run_tag_if(struct dhcp_netid *tags)
|
|
||||||
{
|
|
||||||
struct tag_if *exprs;
|
|
||||||
struct dhcp_netid_list *list;
|
|
||||||
|
|
||||||
for (exprs = daemon->tag_if; exprs; exprs = exprs->next)
|
|
||||||
if (match_netid(exprs->tag, tags, 1))
|
|
||||||
for (list = exprs->set; list; list = list->next)
|
|
||||||
{
|
|
||||||
list->list->next = tags;
|
|
||||||
tags = list->list;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
int address_allocate(struct dhcp_context *context,
|
int address_allocate(struct dhcp_context *context,
|
||||||
struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
|
struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
|
||||||
struct dhcp_netid *netids, time_t now)
|
struct dhcp_netid *netids, time_t now)
|
||||||
@@ -850,7 +759,7 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
|||||||
is_addr_in_context(context, config))
|
is_addr_in_context(context, config))
|
||||||
return config;
|
return config;
|
||||||
|
|
||||||
/* use match with fewest wildcast octets */
|
/* use match with fewest wildcard octets */
|
||||||
for (candidate = NULL, count = 0, config = configs; config; config = config->next)
|
for (candidate = NULL, count = 0, config = configs; config; config = config->next)
|
||||||
if (is_addr_in_context(context, config))
|
if (is_addr_in_context(context, config))
|
||||||
for (conf_addr = config->hwaddr; conf_addr; conf_addr = conf_addr->next)
|
for (conf_addr = config->hwaddr; conf_addr; conf_addr = conf_addr->next)
|
||||||
@@ -1027,85 +936,6 @@ void dhcp_read_ethers(void)
|
|||||||
my_syslog(MS_DHCP | LOG_INFO, _("read %s - %d addresses"), ETHERSFILE, count);
|
my_syslog(MS_DHCP | LOG_INFO, _("read %s - %d addresses"), ETHERSFILE, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_dhcp_hosts(int fatal)
|
|
||||||
{
|
|
||||||
/* If the same IP appears in more than one host config, then DISCOVER
|
|
||||||
for one of the hosts will get the address, but REQUEST will be NAKed,
|
|
||||||
since the address is reserved by the other one -> protocol loop.
|
|
||||||
Also check that FQDNs match the domain we are using. */
|
|
||||||
|
|
||||||
struct dhcp_config *configs, *cp;
|
|
||||||
|
|
||||||
for (configs = daemon->dhcp_conf; configs; configs = configs->next)
|
|
||||||
{
|
|
||||||
char *domain;
|
|
||||||
|
|
||||||
if ((configs->flags & DHOPT_BANK) || fatal)
|
|
||||||
{
|
|
||||||
for (cp = configs->next; cp; cp = cp->next)
|
|
||||||
if ((configs->flags & cp->flags & CONFIG_ADDR) && configs->addr.s_addr == cp->addr.s_addr)
|
|
||||||
{
|
|
||||||
if (fatal)
|
|
||||||
die(_("duplicate IP address %s in dhcp-config directive."),
|
|
||||||
inet_ntoa(cp->addr), EC_BADCONF);
|
|
||||||
else
|
|
||||||
my_syslog(MS_DHCP | LOG_ERR, _("duplicate IP address %s in %s."),
|
|
||||||
inet_ntoa(cp->addr), daemon->dhcp_hosts_file);
|
|
||||||
configs->flags &= ~CONFIG_ADDR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* split off domain part */
|
|
||||||
if ((configs->flags & CONFIG_NAME) && (domain = strip_hostname(configs->hostname)))
|
|
||||||
configs->domain = domain;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dhcp_update_configs(struct dhcp_config *configs)
|
|
||||||
{
|
|
||||||
/* Some people like to keep all static IP addresses in /etc/hosts.
|
|
||||||
This goes through /etc/hosts and sets static addresses for any DHCP config
|
|
||||||
records which don't have an address and whose name matches.
|
|
||||||
We take care to maintain the invariant that any IP address can appear
|
|
||||||
in at most one dhcp-host. Since /etc/hosts can be re-read by SIGHUP,
|
|
||||||
restore the status-quo ante first. */
|
|
||||||
|
|
||||||
struct dhcp_config *config;
|
|
||||||
struct crec *crec;
|
|
||||||
|
|
||||||
for (config = configs; config; config = config->next)
|
|
||||||
if (config->flags & CONFIG_ADDR_HOSTS)
|
|
||||||
config->flags &= ~(CONFIG_ADDR | CONFIG_ADDR_HOSTS);
|
|
||||||
|
|
||||||
|
|
||||||
if (daemon->port != 0)
|
|
||||||
for (config = configs; config; config = config->next)
|
|
||||||
if (!(config->flags & CONFIG_ADDR) &&
|
|
||||||
(config->flags & CONFIG_NAME) &&
|
|
||||||
(crec = cache_find_by_name(NULL, config->hostname, 0, F_IPV4)) &&
|
|
||||||
(crec->flags & F_HOSTS))
|
|
||||||
{
|
|
||||||
if (cache_find_by_name(crec, config->hostname, 0, F_IPV4))
|
|
||||||
{
|
|
||||||
/* use primary (first) address */
|
|
||||||
while (crec && !(crec->flags & F_REVERSE))
|
|
||||||
crec = cache_find_by_name(crec, config->hostname, 0, F_IPV4);
|
|
||||||
if (!crec)
|
|
||||||
continue; /* should be never */
|
|
||||||
my_syslog(MS_DHCP | LOG_WARNING, _("%s has more than one address in hostsfile, using %s for DHCP"),
|
|
||||||
config->hostname, inet_ntoa(crec->addr.addr.addr.addr4));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config_find_by_address(configs, crec->addr.addr.addr.addr4))
|
|
||||||
my_syslog(MS_DHCP | LOG_WARNING, _("duplicate IP address %s (%s) in dhcp-config directive"),
|
|
||||||
inet_ntoa(crec->addr.addr.addr.addr4), config->hostname);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
config->addr = crec->addr.addr.addr.addr4;
|
|
||||||
config->flags |= CONFIG_ADDR | CONFIG_ADDR_HOSTS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we've not found a hostname any other way, try and see if there's one in /etc/hosts
|
/* If we've not found a hostname any other way, try and see if there's one in /etc/hosts
|
||||||
for this address. If it has a domain part, that must match the set domain and
|
for this address. If it has a domain part, that must match the set domain and
|
||||||
@@ -1146,20 +976,5 @@ char *host_from_dns(struct in_addr addr)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return domain or NULL if none. */
|
|
||||||
char *strip_hostname(char *hostname)
|
|
||||||
{
|
|
||||||
char *dot = strchr(hostname, '.');
|
|
||||||
|
|
||||||
if (!dot)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*dot = 0; /* truncate */
|
|
||||||
if (strlen(dot+1) != 0)
|
|
||||||
return dot+1;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -53,3 +53,16 @@
|
|||||||
#define OPTION6_INTERFACE_ID 18
|
#define OPTION6_INTERFACE_ID 18
|
||||||
#define OPTION6_RECONFIGURE_MSG 19
|
#define OPTION6_RECONFIGURE_MSG 19
|
||||||
#define OPTION6_RECONF_ACCEPT 20
|
#define OPTION6_RECONF_ACCEPT 20
|
||||||
|
#define OPTION6_DNS_SERVER 23
|
||||||
|
#define OPTION6_DOMAIN_SEARCH 24
|
||||||
|
#define OPTION6_REMOTE_ID 37
|
||||||
|
#define OPTION6_SUBSCRIBER_ID 38
|
||||||
|
#define OPTION6_FQDN 39
|
||||||
|
|
||||||
|
#define DHCP6SUCCESS 0
|
||||||
|
#define DHCP6UNSPEC 1
|
||||||
|
#define DHCP6NOADDRS 2
|
||||||
|
#define DHCP6NOBINDING 3
|
||||||
|
#define DHCP6NOTONLINK 4
|
||||||
|
#define DHCP6USEMULTI 5
|
||||||
|
|
||||||
+575
-104
@@ -20,30 +20,51 @@
|
|||||||
|
|
||||||
struct iface_param {
|
struct iface_param {
|
||||||
struct dhcp_context *current;
|
struct dhcp_context *current;
|
||||||
int ind;
|
struct in6_addr fallback;
|
||||||
|
int ind, addr_match;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int join_multicast(struct in6_addr *local, int prefix,
|
|
||||||
int scope, int if_index, void *vparam);
|
|
||||||
|
|
||||||
static int complete_context6(struct in6_addr *local, int prefix,
|
static int complete_context6(struct in6_addr *local, int prefix,
|
||||||
int scope, int if_index, void *vparam);
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam);
|
||||||
|
|
||||||
|
static int make_duid1(int index, unsigned int type, char *mac, size_t maclen, void *parm);
|
||||||
|
|
||||||
void dhcp6_init(void)
|
void dhcp6_init(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_in6 saddr;
|
struct sockaddr_in6 saddr;
|
||||||
|
#if defined(IPV6_TCLASS) && defined(IPTOS_CLASS_CS6)
|
||||||
int class = IPTOS_CLASS_CS6;
|
int class = IPTOS_CLASS_CS6;
|
||||||
|
#endif
|
||||||
|
int oneopt = 1;
|
||||||
|
|
||||||
if ((fd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1 ||
|
if ((fd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1 ||
|
||||||
|
#if defined(IPV6_TCLASS) && defined(IPTOS_CLASS_CS6)
|
||||||
setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &class, sizeof(class)) == -1 ||
|
setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &class, sizeof(class)) == -1 ||
|
||||||
|
#endif
|
||||||
|
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &oneopt, sizeof(oneopt)) == -1 ||
|
||||||
!fix_fd(fd) ||
|
!fix_fd(fd) ||
|
||||||
!set_ipv6pktinfo(fd))
|
!set_ipv6pktinfo(fd))
|
||||||
die (_("cannot create DHCPv6 socket: %s"), NULL, EC_BADNET);
|
die (_("cannot create DHCPv6 socket: %s"), NULL, EC_BADNET);
|
||||||
|
|
||||||
|
/* When bind-interfaces is set, there might be more than one dnmsasq
|
||||||
|
instance binding port 547. That's OK if they serve different networks.
|
||||||
|
Need to set REUSEADDR to make this posible, or REUSEPORT on *BSD. */
|
||||||
|
if (option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND))
|
||||||
|
{
|
||||||
|
#ifdef SO_REUSEPORT
|
||||||
|
int rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &oneopt, sizeof(oneopt));
|
||||||
|
#else
|
||||||
|
int rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &oneopt, sizeof(oneopt));
|
||||||
|
#endif
|
||||||
|
if (rc == -1)
|
||||||
|
die(_("failed to set SO_REUSE{ADDR|PORT} on DHCPv6 socket: %s"), NULL, EC_BADNET);
|
||||||
|
}
|
||||||
|
|
||||||
memset(&saddr, 0, sizeof(saddr));
|
memset(&saddr, 0, sizeof(saddr));
|
||||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
saddr.sin6_len = sizeof(addr.in6);
|
saddr.sin6_len = sizeof(struct sockaddr_in6);
|
||||||
#endif
|
#endif
|
||||||
saddr.sin6_family = AF_INET6;
|
saddr.sin6_family = AF_INET6;
|
||||||
saddr.sin6_addr = in6addr_any;
|
saddr.sin6_addr = in6addr_any;
|
||||||
@@ -52,64 +73,9 @@ void dhcp6_init(void)
|
|||||||
if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in6)))
|
if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in6)))
|
||||||
die(_("failed to bind DHCPv6 server socket: %s"), NULL, EC_BADNET);
|
die(_("failed to bind DHCPv6 server socket: %s"), NULL, EC_BADNET);
|
||||||
|
|
||||||
/* join multicast groups on each interface we're interested in */
|
|
||||||
if (!iface_enumerate(AF_INET6, &fd, join_multicast))
|
|
||||||
die(_("failed to join DHCPv6 multicast group: %s"), NULL, EC_BADNET);
|
|
||||||
|
|
||||||
daemon->dhcp6fd = fd;
|
daemon->dhcp6fd = fd;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int join_multicast(struct in6_addr *local, int prefix,
|
|
||||||
int scope, int if_index, void *vparam)
|
|
||||||
{
|
|
||||||
char ifrn_name[IFNAMSIZ];
|
|
||||||
struct ipv6_mreq mreq;
|
|
||||||
struct in6_addr maddr;
|
|
||||||
int fd = *((int *)vparam);
|
|
||||||
struct dhcp_context *context;
|
|
||||||
struct iname *tmp;
|
|
||||||
|
|
||||||
(void)prefix;
|
|
||||||
(void)scope; /* warnings */
|
|
||||||
|
|
||||||
if (!indextoname(fd, if_index, ifrn_name))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Are we doing DHCP on this interface? */
|
|
||||||
if (!iface_check(AF_INET6, (struct all_addr *)local, ifrn_name))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
|
||||||
if (tmp->name && (strcmp(tmp->name, ifrn_name) == 0))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* weird libvirt-inspired access control */
|
|
||||||
for (context = daemon->dhcp; context; context = context->next)
|
|
||||||
if (!context->interface || strcmp(context->interface, ifrn_name) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!context)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
mreq.ipv6mr_interface = if_index;
|
|
||||||
inet_pton(AF_INET6, ALL_RELAY_AGENTS_AND_SERVERS, &maddr);
|
|
||||||
|
|
||||||
if (!setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
inet_pton(AF_INET6, ALL_SERVERS, &maddr);
|
|
||||||
|
|
||||||
if (!setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void dhcp6_packet(time_t now)
|
void dhcp6_packet(time_t now)
|
||||||
{
|
{
|
||||||
struct dhcp_context *context;
|
struct dhcp_context *context;
|
||||||
@@ -121,11 +87,11 @@ void dhcp6_packet(time_t now)
|
|||||||
struct cmsghdr align; /* this ensures alignment */
|
struct cmsghdr align; /* this ensures alignment */
|
||||||
char control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
char control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
||||||
} control_u;
|
} control_u;
|
||||||
union mysockaddr from;
|
struct sockaddr_in6 from;
|
||||||
struct all_addr dest;
|
|
||||||
ssize_t sz;
|
ssize_t sz;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
struct iname *tmp;
|
struct iname *tmp;
|
||||||
|
unsigned short port;
|
||||||
|
|
||||||
msg.msg_control = control_u.control6;
|
msg.msg_control = control_u.control6;
|
||||||
msg.msg_controllen = sizeof(control_u);
|
msg.msg_controllen = sizeof(control_u);
|
||||||
@@ -135,7 +101,7 @@ void dhcp6_packet(time_t now)
|
|||||||
msg.msg_iov = &daemon->dhcp_packet;
|
msg.msg_iov = &daemon->dhcp_packet;
|
||||||
msg.msg_iovlen = 1;
|
msg.msg_iovlen = 1;
|
||||||
|
|
||||||
if ((sz = recv_dhcp_packet(daemon->dhcp6fd, &msg) == -1) || sz <= 4)
|
if ((sz = recv_dhcp_packet(daemon->dhcp6fd, &msg)) == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
|
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
|
||||||
@@ -148,73 +114,578 @@ void dhcp6_packet(time_t now)
|
|||||||
p.c = CMSG_DATA(cmptr);
|
p.c = CMSG_DATA(cmptr);
|
||||||
|
|
||||||
if_index = p.p->ipi6_ifindex;
|
if_index = p.p->ipi6_ifindex;
|
||||||
dest.addr.addr6 = p.p->ipi6_addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!indextoname(daemon->dhcp6fd, if_index, ifr.ifr_name))
|
if (!indextoname(daemon->dhcp6fd, if_index, ifr.ifr_name))
|
||||||
return;
|
return;
|
||||||
ls -l
|
|
||||||
if (!iface_check(AF_INET6, (struct all_addr *)&dest, ifr.ifr_name))
|
for (tmp = daemon->if_except; tmp; tmp = tmp->next)
|
||||||
return;
|
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
||||||
|
return;
|
||||||
|
|
||||||
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
||||||
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* weird libvirt-inspired access control */
|
|
||||||
for (context = daemon->dhcp; context; context = context->next)
|
|
||||||
if (!context->interface || strcmp(context->interface, ifr.ifr_name) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!context)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* unlinked contexts are marked by context->current == context */
|
|
||||||
for (context = daemon->dhcp; context; context = context->next)
|
|
||||||
context->current = context;
|
|
||||||
|
|
||||||
parm.current = NULL;
|
parm.current = NULL;
|
||||||
parm.ind = if_index;
|
parm.ind = if_index;
|
||||||
|
parm.addr_match = 0;
|
||||||
|
memset(&parm.fallback, 0, IN6ADDRSZ);
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if (IN6_IS_ADDR_UNSPECIFIED(&context->start6) && context->prefix == 0)
|
||||||
|
{
|
||||||
|
/* wildcard context for DHCP-stateless only */
|
||||||
|
parm.current = context;
|
||||||
|
context->current = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* unlinked contexts are marked by context->current == context */
|
||||||
|
context->current = context;
|
||||||
|
memset(&context->local6, 0, IN6ADDRSZ);
|
||||||
|
}
|
||||||
|
|
||||||
if (!iface_enumerate(AF_INET6, &parm, complete_context6))
|
if (!iface_enumerate(AF_INET6, &parm, complete_context6))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (daemon->if_names || daemon->if_addrs)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (tmp = daemon->if_names; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!tmp && !parm.addr_match)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lease_prune(NULL, now); /* lose any expired leases */
|
lease_prune(NULL, now); /* lose any expired leases */
|
||||||
|
|
||||||
msg.msg_iov = &daemon->dhcp_packet;
|
port = dhcp6_reply(parm.current, if_index, ifr.ifr_name, &parm.fallback,
|
||||||
sz = dhcp6_reply(parm.current, sz);
|
sz, IN6_IS_ADDR_MULTICAST(&from.sin6_addr), now);
|
||||||
/* ifr.ifr_name, if_index, (size_t)sz,
|
|
||||||
now, unicast_dest, &is_inform, pxe_fd, iface_addr); */
|
|
||||||
lease_update_file(now);
|
|
||||||
lease_update_dns();
|
|
||||||
|
|
||||||
if (sz != 0)
|
lease_update_file(now);
|
||||||
send_from(daemon->dhcp6fd, 0, daemon->outpacket.iov_base, sz, &from, &dest, if_index);
|
lease_update_dns(0);
|
||||||
|
|
||||||
|
/* The port in the source address of the original request should
|
||||||
|
be correct, but at least once client sends from the server port,
|
||||||
|
so we explicitly send to the client port to a client, and the
|
||||||
|
server port to a relay. */
|
||||||
|
if (port != 0)
|
||||||
|
{
|
||||||
|
from.sin6_port = htons(port);
|
||||||
|
while (sendto(daemon->dhcp6fd, daemon->outpacket.iov_base, save_counter(0),
|
||||||
|
0, (struct sockaddr *)&from, sizeof(from)) == -1 &&
|
||||||
|
retry_send());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int complete_context6(struct in6_addr *local, int prefix,
|
static int complete_context6(struct in6_addr *local, int prefix,
|
||||||
int scope, int if_index, void *vparam)
|
int scope, int if_index, int dad, int preferred,
|
||||||
|
int valid, void *vparam)
|
||||||
{
|
{
|
||||||
struct dhcp_context *context;
|
struct dhcp_context *context;
|
||||||
struct iface_param *param = vparam;
|
struct iface_param *param = vparam;
|
||||||
|
struct iname *tmp;
|
||||||
for (context = daemon->dhcp6; context; context = context->next)
|
|
||||||
|
(void)scope; /* warning */
|
||||||
|
(void)dad;
|
||||||
|
(void)preferred;
|
||||||
|
(void)valid;
|
||||||
|
|
||||||
|
if (if_index == param->ind &&
|
||||||
|
!IN6_IS_ADDR_LOOPBACK(local) &&
|
||||||
|
!IN6_IS_ADDR_LINKLOCAL(local) &&
|
||||||
|
!IN6_IS_ADDR_MULTICAST(local))
|
||||||
{
|
{
|
||||||
if ((context->flags & CONTEXT_IPV6) &&
|
/* if we have --listen-address config, see if the
|
||||||
prefix == context->prefix &&
|
arrival interface has a matching address. */
|
||||||
is_same_net6(local, &context->start6, prefix) &&
|
for (tmp = daemon->if_addrs; tmp; tmp = tmp->next)
|
||||||
is_same_net6(local, &context->end6, prefix))
|
if (tmp->addr.sa.sa_family == AF_INET6 &&
|
||||||
{
|
IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr, local))
|
||||||
/* link it onto the current chain if we've not seen it before */
|
param->addr_match = 1;
|
||||||
if (if_index == param->ind && context->current == context)
|
|
||||||
{
|
/* Determine a globally address on the arrival interface, even
|
||||||
context->current = param->current;
|
if we have no matching dhcp-context, because we're only
|
||||||
param->current = context;
|
allocating on remote subnets via relays. This
|
||||||
}
|
is used as a default for the DNS server option. */
|
||||||
|
param->fallback = *local;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
{
|
||||||
|
if (!(context->flags & CONTEXT_TEMPLATE) &&
|
||||||
|
prefix == context->prefix &&
|
||||||
|
is_same_net6(local, &context->start6, prefix) &&
|
||||||
|
is_same_net6(local, &context->end6, prefix))
|
||||||
|
{
|
||||||
|
/* link it onto the current chain if we've not seen it before */
|
||||||
|
if (context->current == context)
|
||||||
|
{
|
||||||
|
context->current = param->current;
|
||||||
|
param->current = context;
|
||||||
|
context->local6 = *local;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct dhcp_config *config_find_by_address6(struct dhcp_config *configs, struct in6_addr *net, int prefix, u64 addr)
|
||||||
|
{
|
||||||
|
struct dhcp_config *config;
|
||||||
|
|
||||||
|
for (config = configs; config; config = config->next)
|
||||||
|
if ((config->flags & CONFIG_ADDR6) &&
|
||||||
|
is_same_net6(&config->addr6, net, prefix) &&
|
||||||
|
(prefix == 128 || addr6part(&config->addr6) == addr))
|
||||||
|
return config;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len,
|
||||||
|
int serial, struct dhcp_netid *netids, struct in6_addr *ans)
|
||||||
|
{
|
||||||
|
/* Find a free address: exclude anything in use and anything allocated to
|
||||||
|
a particular hwaddr/clientid/hostname in our configuration.
|
||||||
|
Try to return from contexts which match netids first.
|
||||||
|
|
||||||
|
Note that we assume the address prefix lengths are 64 or greater, so we can
|
||||||
|
get by with 64 bit arithmetic.
|
||||||
|
*/
|
||||||
|
|
||||||
|
u64 start, addr;
|
||||||
|
struct dhcp_context *c, *d;
|
||||||
|
int i, pass;
|
||||||
|
u64 j;
|
||||||
|
|
||||||
|
/* hash hwaddr: use the SDBM hashing algorithm. This works
|
||||||
|
for MAC addresses, let's see how it manages with client-ids! */
|
||||||
|
for (j = 0, i = 0; i < clid_len; i++)
|
||||||
|
j += clid[i] + (j << 6) + (j << 16) - j;
|
||||||
|
|
||||||
|
for (pass = 0; pass <= 1; pass++)
|
||||||
|
for (c = context; c; c = c->current)
|
||||||
|
if (c->flags & (CONTEXT_DEPRECATE | CONTEXT_STATIC | CONTEXT_RA_STATELESS))
|
||||||
|
continue;
|
||||||
|
else if (!match_netid(c->filter, netids, pass))
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (option_bool(OPT_CONSEC_ADDR))
|
||||||
|
/* seed is largest extant lease addr in this context */
|
||||||
|
start = lease_find_max_addr6(c) + serial;
|
||||||
|
else
|
||||||
|
start = addr6part(&c->start6) + ((j + c->addr_epoch + serial) % (1 + addr6part(&c->end6) - addr6part(&c->start6)));
|
||||||
|
|
||||||
|
/* iterate until we find a free address. */
|
||||||
|
addr = start;
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* eliminate addresses in use by the server. */
|
||||||
|
for (d = context; d; d = d->current)
|
||||||
|
if (addr == addr6part(&d->local6))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!d &&
|
||||||
|
!lease6_find_by_addr(&c->start6, c->prefix, addr) &&
|
||||||
|
!config_find_by_address6(daemon->dhcp_conf, &c->start6, c->prefix, addr))
|
||||||
|
{
|
||||||
|
*ans = c->start6;
|
||||||
|
setaddr6part (ans, addr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
addr++;
|
||||||
|
|
||||||
|
if (addr == addr6part(&c->end6) + 1)
|
||||||
|
addr = addr6part(&c->start6);
|
||||||
|
|
||||||
|
} while (addr != start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dhcp_context *address6_available(struct dhcp_context *context,
|
||||||
|
struct in6_addr *taddr,
|
||||||
|
struct dhcp_netid *netids)
|
||||||
|
{
|
||||||
|
u64 start, end, addr = addr6part(taddr);
|
||||||
|
struct dhcp_context *tmp;
|
||||||
|
|
||||||
|
for (tmp = context; tmp; tmp = tmp->current)
|
||||||
|
{
|
||||||
|
start = addr6part(&tmp->start6);
|
||||||
|
end = addr6part(&tmp->end6);
|
||||||
|
|
||||||
|
if (!(tmp->flags & (CONTEXT_STATIC | CONTEXT_RA_STATELESS)) &&
|
||||||
|
is_same_net6(&tmp->start6, taddr, tmp->prefix) &&
|
||||||
|
is_same_net6(&tmp->end6, taddr, tmp->prefix) &&
|
||||||
|
addr >= start &&
|
||||||
|
addr <= end &&
|
||||||
|
match_netid(tmp->filter, netids, 1))
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dhcp_context *narrow_context6(struct dhcp_context *context,
|
||||||
|
struct in6_addr *taddr,
|
||||||
|
struct dhcp_netid *netids)
|
||||||
|
{
|
||||||
|
/* We start of with a set of possible contexts, all on the current physical interface.
|
||||||
|
These are chained on ->current.
|
||||||
|
Here we have an address, and return the actual context correponding to that
|
||||||
|
address. Note that none may fit, if the address came a dhcp-host and is outside
|
||||||
|
any dhcp-range. In that case we return a static range if possible, or failing that,
|
||||||
|
any context on the correct subnet. (If there's more than one, this is a dodgy
|
||||||
|
configuration: maybe there should be a warning.) */
|
||||||
|
|
||||||
|
struct dhcp_context *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = address6_available(context, taddr, netids)))
|
||||||
|
{
|
||||||
|
for (tmp = context; tmp; tmp = tmp->current)
|
||||||
|
if (match_netid(tmp->filter, netids, 1) &&
|
||||||
|
is_same_net6(taddr, &tmp->start6, tmp->prefix) &&
|
||||||
|
(tmp->flags & CONTEXT_STATIC))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!tmp)
|
||||||
|
for (tmp = context; tmp; tmp = tmp->current)
|
||||||
|
if (match_netid(tmp->filter, netids, 1) &&
|
||||||
|
is_same_net6(taddr, &tmp->start6, tmp->prefix) &&
|
||||||
|
!(tmp->flags & CONTEXT_PROXY))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only one context allowed now */
|
||||||
|
if (tmp)
|
||||||
|
tmp->current = NULL;
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_config_in_context6(struct dhcp_context *context, struct dhcp_config *config)
|
||||||
|
{
|
||||||
|
if (!context) /* called via find_config() from lease_update_from_configs() */
|
||||||
|
return 1;
|
||||||
|
if (!(config->flags & CONFIG_ADDR6) || is_addr_in_context6(context, &config->addr6))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int is_addr_in_context6(struct dhcp_context *context, struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
for (; context; context = context->current)
|
||||||
|
if (is_same_net6(addr, &context->start6, context->prefix))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct dhcp_config *find_config6(struct dhcp_config *configs,
|
||||||
|
struct dhcp_context *context,
|
||||||
|
unsigned char *duid, int duid_len,
|
||||||
|
char *hostname)
|
||||||
|
{
|
||||||
|
struct dhcp_config *config;
|
||||||
|
|
||||||
|
if (duid)
|
||||||
|
for (config = configs; config; config = config->next)
|
||||||
|
if (config->flags & CONFIG_CLID)
|
||||||
|
{
|
||||||
|
if (config->clid_len == duid_len &&
|
||||||
|
memcmp(config->clid, duid, duid_len) == 0 &&
|
||||||
|
is_config_in_context6(context, config))
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hostname && context)
|
||||||
|
for (config = configs; config; config = config->next)
|
||||||
|
if ((config->flags & CONFIG_NAME) &&
|
||||||
|
hostname_isequal(config->hostname, hostname) &&
|
||||||
|
is_config_in_context6(context, config))
|
||||||
|
return config;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void make_duid(time_t now)
|
||||||
|
{
|
||||||
|
if (daemon->duid_config)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
daemon->duid = p = safe_malloc(daemon->duid_config_len + 6);
|
||||||
|
daemon->duid_len = daemon->duid_config_len + 6;
|
||||||
|
PUTSHORT(2, p); /* DUID_EN */
|
||||||
|
PUTLONG(daemon->duid_enterprise, p);
|
||||||
|
memcpy(p, daemon->duid_config, daemon->duid_config_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* rebase epoch to 1/1/2000 */
|
||||||
|
time_t newnow = now - 946684800;
|
||||||
|
|
||||||
|
iface_enumerate(AF_LOCAL, &newnow, make_duid1);
|
||||||
|
|
||||||
|
if(!daemon->duid)
|
||||||
|
die("Cannot create DHCPv6 server DUID: %s", NULL, EC_MISC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int make_duid1(int index, unsigned int type, char *mac, size_t maclen, void *parm)
|
||||||
|
{
|
||||||
|
/* create DUID as specified in RFC3315. We use the MAC of the
|
||||||
|
first interface we find that isn't loopback or P-to-P and
|
||||||
|
has address-type < 256. Address types above 256 are things like
|
||||||
|
tunnels which don't have usable MAC addresses. */
|
||||||
|
|
||||||
|
unsigned char *p;
|
||||||
|
(void)index;
|
||||||
|
|
||||||
|
if (type >= 256)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
#ifdef HAVE_BROKEN_RTC
|
||||||
|
daemon->duid = p = safe_malloc(maclen + 4);
|
||||||
|
daemon->duid_len = maclen + 4;
|
||||||
|
PUTSHORT(3, p); /* DUID_LL */
|
||||||
|
PUTSHORT(type, p); /* address type */
|
||||||
|
#else
|
||||||
|
daemon->duid = p = safe_malloc(maclen + 8);
|
||||||
|
daemon->duid_len = maclen + 8;
|
||||||
|
PUTSHORT(1, p); /* DUID_LLT */
|
||||||
|
PUTSHORT(type, p); /* address type */
|
||||||
|
PUTLONG(*((time_t *)parm), p); /* time */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memcpy(p, mac, maclen);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cparam {
|
||||||
|
time_t now;
|
||||||
|
int newone;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int construct_worker(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam)
|
||||||
|
{
|
||||||
|
char ifrn_name[IFNAMSIZ];
|
||||||
|
struct in6_addr start6, end6;
|
||||||
|
struct dhcp_context *template, *context;
|
||||||
|
|
||||||
|
(void)scope;
|
||||||
|
(void)dad;
|
||||||
|
|
||||||
|
struct cparam *param = vparam;
|
||||||
|
|
||||||
|
if (IN6_IS_ADDR_LOOPBACK(local) ||
|
||||||
|
IN6_IS_ADDR_LINKLOCAL(local) ||
|
||||||
|
IN6_IS_ADDR_MULTICAST(local))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!indextoname(daemon->doing_dhcp6 ? daemon->dhcp6fd : daemon->icmp6fd, if_index, ifrn_name))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (template = daemon->dhcp6; template; template = template->next)
|
||||||
|
if (!(template->flags & CONTEXT_TEMPLATE))
|
||||||
|
{
|
||||||
|
/* non-template entries, just fill in interface and local addresses */
|
||||||
|
if (prefix == template->prefix &&
|
||||||
|
is_same_net6(local, &template->start6, prefix) &&
|
||||||
|
is_same_net6(local, &template->end6, prefix))
|
||||||
|
{
|
||||||
|
template->if_index = if_index;
|
||||||
|
template->local6 = *local;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (strcmp(ifrn_name, template->template_interface) == 0 &&
|
||||||
|
addr6part(local) == addr6part(&template->start6))
|
||||||
|
{
|
||||||
|
start6 = *local;
|
||||||
|
setaddr6part(&start6, addr6part(&template->start6));
|
||||||
|
end6 = *local;
|
||||||
|
setaddr6part(&end6, addr6part(&template->end6));
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if ((context->flags & CONTEXT_CONSTRUCTED) &&
|
||||||
|
IN6_ARE_ADDR_EQUAL(&start6, &context->start6) &&
|
||||||
|
IN6_ARE_ADDR_EQUAL(&end6, &context->end6))
|
||||||
|
{
|
||||||
|
context->flags &= ~CONTEXT_GC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context && (context = whine_malloc(sizeof (struct dhcp_context))))
|
||||||
|
{
|
||||||
|
*context = *template;
|
||||||
|
context->start6 = start6;
|
||||||
|
context->end6 = end6;
|
||||||
|
context->flags &= ~CONTEXT_TEMPLATE;
|
||||||
|
context->flags |= CONTEXT_CONSTRUCTED;
|
||||||
|
context->if_index = if_index;
|
||||||
|
context->local6 = *local;
|
||||||
|
|
||||||
|
context->next = daemon->dhcp6;
|
||||||
|
daemon->dhcp6 = context;
|
||||||
|
|
||||||
|
ra_start_unsolicted(param->now, context);
|
||||||
|
/* we created a new one, need to call
|
||||||
|
lease_update_file to get periodic functions called */
|
||||||
|
param->newone = 1;
|
||||||
|
|
||||||
|
log_context(AF_INET6, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context)
|
||||||
|
{
|
||||||
|
if (valid == -1)
|
||||||
|
context->valid = valid;
|
||||||
|
else
|
||||||
|
context->valid = valid + param->now;
|
||||||
|
|
||||||
|
if (preferred == -1)
|
||||||
|
context->preferred = preferred;
|
||||||
|
else
|
||||||
|
context->preferred = preferred + param->now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dhcp_construct_contexts(time_t now)
|
||||||
|
{
|
||||||
|
struct dhcp_context *tmp, *context, **up;
|
||||||
|
struct cparam param;
|
||||||
|
param.newone = 0;
|
||||||
|
param.now = now;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if (context->flags & CONTEXT_CONSTRUCTED)
|
||||||
|
{
|
||||||
|
context->flags |= CONTEXT_GC;
|
||||||
|
context->if_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
iface_enumerate(AF_INET6, ¶m, construct_worker);
|
||||||
|
|
||||||
|
for (up = &daemon->dhcp6, context = daemon->dhcp6; context; context = tmp)
|
||||||
|
{
|
||||||
|
tmp = context->next;
|
||||||
|
|
||||||
|
if (context->flags & CONTEXT_GC)
|
||||||
|
{
|
||||||
|
if (daemon->dhcp6 == context)
|
||||||
|
daemon->dhcp6 = context->next;
|
||||||
|
*up = context->next;
|
||||||
|
free(context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
up = &context->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.newone)
|
||||||
|
{
|
||||||
|
if (daemon->dhcp || daemon->doing_dhcp6)
|
||||||
|
lease_update_file(now);
|
||||||
|
else
|
||||||
|
/* Not doing DHCP, so no lease system, manage alarms for ra only */
|
||||||
|
send_alarm(periodic_ra(now), now);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int join_multicast_worker(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam)
|
||||||
|
{
|
||||||
|
char ifrn_name[IFNAMSIZ];
|
||||||
|
struct ipv6_mreq mreq;
|
||||||
|
int fd, i, max = *((int *)vparam);
|
||||||
|
struct iname *tmp;
|
||||||
|
|
||||||
|
(void)prefix;
|
||||||
|
(void)scope;
|
||||||
|
(void)dad;
|
||||||
|
(void)preferred;
|
||||||
|
(void)valid;
|
||||||
|
|
||||||
|
/* record which interfaces we join on, so that we do it at most one per
|
||||||
|
interface, even when they have multiple addresses. Use outpacket
|
||||||
|
as an array of int, since it's always allocated here and easy
|
||||||
|
to expand for theoretical vast numbers of interfaces. */
|
||||||
|
for (i = 0; i < max; i++)
|
||||||
|
if (if_index == ((int *)daemon->outpacket.iov_base)[i])
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if ((fd = socket(PF_INET6, SOCK_DGRAM, 0)) == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!indextoname(fd, if_index, ifrn_name))
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
/* Are we doing DHCP on this interface? */
|
||||||
|
if (!iface_check(AF_INET6, (struct all_addr *)local, ifrn_name, NULL))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->name && (strcmp(tmp->name, ifrn_name) == 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
mreq.ipv6mr_interface = if_index;
|
||||||
|
|
||||||
|
inet_pton(AF_INET6, ALL_RELAY_AGENTS_AND_SERVERS, &mreq.ipv6mr_multiaddr);
|
||||||
|
|
||||||
|
if (daemon->doing_dhcp6 &&
|
||||||
|
setsockopt(daemon->dhcp6fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inet_pton(AF_INET6, ALL_SERVERS, &mreq.ipv6mr_multiaddr);
|
||||||
|
|
||||||
|
if (daemon->doing_dhcp6 &&
|
||||||
|
setsockopt(daemon->dhcp6fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inet_pton(AF_INET6, ALL_ROUTERS, &mreq.ipv6mr_multiaddr);
|
||||||
|
|
||||||
|
if (daemon->doing_ra &&
|
||||||
|
setsockopt(daemon->icmp6fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
expand_buf(&daemon->outpacket, (max+1) * sizeof(int));
|
||||||
|
((int *)daemon->outpacket.iov_base)[max++] = if_index;
|
||||||
|
|
||||||
|
*((int *)vparam) = max;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void join_multicast(void)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (!iface_enumerate(AF_INET6, &count, join_multicast_worker))
|
||||||
|
die(_("failed to join DHCPv6 multicast group: %s"), NULL, EC_BADNET);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@
|
|||||||
#define T_OPT 41
|
#define T_OPT 41
|
||||||
#define T_TKEY 249
|
#define T_TKEY 249
|
||||||
#define T_TSIG 250
|
#define T_TSIG 250
|
||||||
|
#define T_AXFR 252
|
||||||
#define T_MAILB 253
|
#define T_MAILB 253
|
||||||
#define T_ANY 255
|
#define T_ANY 255
|
||||||
|
|
||||||
+308
-73
@@ -51,6 +51,7 @@ int main (int argc, char **argv)
|
|||||||
cap_user_header_t hdr = NULL;
|
cap_user_header_t hdr = NULL;
|
||||||
cap_user_data_t data = NULL;
|
cap_user_data_t data = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
struct dhcp_context *context;
|
||||||
|
|
||||||
#ifdef LOCALEDIR
|
#ifdef LOCALEDIR
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
@@ -84,33 +85,49 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
daemon->addrbuff = safe_malloc(ADDRSTRLEN);
|
daemon->addrbuff = safe_malloc(ADDRSTRLEN);
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (!daemon->lease_file)
|
if (!daemon->lease_file)
|
||||||
{
|
{
|
||||||
if (daemon->dhcp)
|
if (daemon->dhcp || daemon->dhcp6)
|
||||||
daemon->lease_file = LEASEFILE;
|
daemon->lease_file = LEASEFILE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Close any file descriptors we inherited apart from std{in|out|err} */
|
/* Close any file descriptors we inherited apart from std{in|out|err}
|
||||||
|
|
||||||
|
Ensure that at least stdin, stdout and stderr (fd 0, 1, 2) exist,
|
||||||
|
otherwise file descriptors we create can end up being 0, 1, or 2
|
||||||
|
and then get accidentally closed later when we make 0, 1, and 2
|
||||||
|
open to /dev/null. Normally we'll be started with 0, 1 and 2 open,
|
||||||
|
but it's not guaranteed. By opening /dev/null three times, we
|
||||||
|
ensure that we're not using those fds for real stuff. */
|
||||||
for (i = 0; i < max_fd; i++)
|
for (i = 0; i < max_fd; i++)
|
||||||
if (i != STDOUT_FILENO && i != STDERR_FILENO && i != STDIN_FILENO)
|
if (i != STDOUT_FILENO && i != STDERR_FILENO && i != STDIN_FILENO)
|
||||||
close(i);
|
close(i);
|
||||||
|
else
|
||||||
|
open("/dev/null", O_RDWR);
|
||||||
|
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifndef HAVE_LINUX_NETWORK
|
||||||
netlink_init();
|
# if !(defined(IP_RECVDSTADDR) && defined(IP_RECVIF) && defined(IP_SENDSRCADDR))
|
||||||
#elif !(defined(IP_RECVDSTADDR) && \
|
|
||||||
defined(IP_RECVIF) && \
|
|
||||||
defined(IP_SENDSRCADDR))
|
|
||||||
if (!option_bool(OPT_NOWILD))
|
if (!option_bool(OPT_NOWILD))
|
||||||
{
|
{
|
||||||
bind_fallback = 1;
|
bind_fallback = 1;
|
||||||
set_option_bool(OPT_NOWILD);
|
set_option_bool(OPT_NOWILD);
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* -- bind-dynamic not supported on !Linux, fall back to --bind-interfaces */
|
||||||
|
if (option_bool(OPT_CLEVERBIND))
|
||||||
|
{
|
||||||
|
bind_fallback = 1;
|
||||||
|
set_option_bool(OPT_NOWILD);
|
||||||
|
reset_option_bool(OPT_CLEVERBIND);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_TFTP
|
#ifndef HAVE_TFTP
|
||||||
if (daemon->tftp_unlimited || daemon->tftp_interfaces)
|
if (option_bool(OPT_TFTP))
|
||||||
die(_("TFTP server not available: set HAVE_TFTP in src/config.h"), NULL, EC_BADCONF);
|
die(_("TFTP server not available: set HAVE_TFTP in src/config.h"), NULL, EC_BADCONF);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -132,38 +149,109 @@ int main (int argc, char **argv)
|
|||||||
die(_("asychronous logging is not available under Android"), NULL, EC_BADCONF);
|
die(_("asychronous logging is not available under Android"), NULL, EC_BADCONF);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_AUTH
|
||||||
|
if (daemon->authserver)
|
||||||
|
die(_("authoritative DNS not available: set HAVE_AUTH in src/config.h"), NULL, EC_BADCONF);
|
||||||
|
#endif
|
||||||
|
|
||||||
rand_init();
|
rand_init();
|
||||||
|
|
||||||
now = dnsmasq_time();
|
now = dnsmasq_time();
|
||||||
|
|
||||||
|
/* Create a serial at startup is not configured. */
|
||||||
|
if (daemon->authinterface && daemon->soa_sn == 0)
|
||||||
|
#ifdef HAVE_BROKEN_RTC
|
||||||
|
die(_("zone serial must be configured in --auth-soa"));
|
||||||
|
#else
|
||||||
|
daemon->soa_sn = now;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (daemon->dhcp)
|
if (daemon->dhcp || daemon->dhcp6)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
# ifdef HAVE_DHCP6
|
||||||
|
if (daemon->dhcp6)
|
||||||
|
{
|
||||||
|
daemon->doing_ra = option_bool(OPT_RA);
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
{
|
||||||
|
if (context->flags & CONTEXT_DHCP)
|
||||||
|
daemon->doing_dhcp6 = 1;
|
||||||
|
if (context->flags & CONTEXT_RA)
|
||||||
|
daemon->doing_ra = 1;
|
||||||
|
#ifndef HAVE_LINUX_NETWORK
|
||||||
|
if (context->flags & CONTEXT_TEMPLATE)
|
||||||
|
die (_("dhcp-range contructor not available on this platform"), NULL, EC_BADCONF);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
/* Note that order matters here, we must call lease_init before
|
/* Note that order matters here, we must call lease_init before
|
||||||
creating any file descriptors which shouldn't be leaked
|
creating any file descriptors which shouldn't be leaked
|
||||||
to the lease-script init process. */
|
to the lease-script init process. We need to call common_init
|
||||||
lease_init(now);
|
before lease_init to allocate buffers it uses.*/
|
||||||
dhcp_init();
|
if (daemon->dhcp || daemon->doing_dhcp6)
|
||||||
|
{
|
||||||
|
dhcp_common_init();
|
||||||
|
lease_init(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (daemon->dhcp)
|
||||||
|
dhcp_init();
|
||||||
|
|
||||||
|
# ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_ra)
|
||||||
|
ra_init(now);
|
||||||
|
|
||||||
|
if (daemon->doing_dhcp6)
|
||||||
|
dhcp6_init();
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
|
netlink_init();
|
||||||
|
|
||||||
|
if (option_bool(OPT_NOWILD) && option_bool(OPT_CLEVERBIND))
|
||||||
|
die(_("cannot set --bind-interfaces and --bind-dynamic"), NULL, EC_BADCONF);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
/* after netlink_init */
|
||||||
|
if (daemon->doing_dhcp6 || daemon->doing_ra)
|
||||||
|
join_multicast();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!enumerate_interfaces())
|
if (!enumerate_interfaces())
|
||||||
die(_("failed to find list of interfaces: %s"), NULL, EC_MISC);
|
die(_("failed to find list of interfaces: %s"), NULL, EC_MISC);
|
||||||
|
|
||||||
if (option_bool(OPT_NOWILD))
|
if (option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND))
|
||||||
{
|
{
|
||||||
create_bound_listeners(1);
|
create_bound_listeners(1);
|
||||||
|
|
||||||
|
if (!option_bool(OPT_CLEVERBIND))
|
||||||
|
for (if_tmp = daemon->if_names; if_tmp; if_tmp = if_tmp->next)
|
||||||
|
if (if_tmp->name && !if_tmp->used)
|
||||||
|
die(_("unknown interface %s"), if_tmp->name, EC_BADNET);
|
||||||
|
|
||||||
for (if_tmp = daemon->if_names; if_tmp; if_tmp = if_tmp->next)
|
#if defined(HAVE_LINUX_NETWORK) && defined(HAVE_DHCP)
|
||||||
if (if_tmp->name && !if_tmp->used)
|
/* after enumerate_interfaces() */
|
||||||
die(_("unknown interface %s"), if_tmp->name, EC_BADNET);
|
if (daemon->dhcp)
|
||||||
|
{
|
||||||
for (if_tmp = daemon->if_addrs; if_tmp; if_tmp = if_tmp->next)
|
bindtodevice(daemon->dhcpfd);
|
||||||
if (!if_tmp->used)
|
if (daemon->enable_pxe)
|
||||||
{
|
bindtodevice(daemon->pxefd);
|
||||||
prettyprint_addr(&if_tmp->addr, daemon->namebuff);
|
}
|
||||||
die(_("no interface with address %s"), daemon->namebuff, EC_BADNET);
|
#endif
|
||||||
}
|
|
||||||
|
#if defined(HAVE_LINUX_NETWORK) && defined(HAVE_DHCP6)
|
||||||
|
if (daemon->dhcp6)
|
||||||
|
bindtodevice(daemon->dhcp6fd);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
create_wildcard_listeners();
|
create_wildcard_listeners();
|
||||||
@@ -189,7 +277,8 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
#if defined(HAVE_SCRIPT)
|
#if defined(HAVE_SCRIPT)
|
||||||
/* Note getpwnam returns static storage */
|
/* Note getpwnam returns static storage */
|
||||||
if (daemon->dhcp && daemon->scriptuser &&
|
if ((daemon->dhcp || daemon->dhcp6) &&
|
||||||
|
daemon->scriptuser &&
|
||||||
(daemon->lease_change_command || daemon->luascript))
|
(daemon->lease_change_command || daemon->luascript))
|
||||||
{
|
{
|
||||||
if ((ent_pw = getpwnam(daemon->scriptuser)))
|
if ((ent_pw = getpwnam(daemon->scriptuser)))
|
||||||
@@ -310,15 +399,48 @@ int main (int argc, char **argv)
|
|||||||
/* write pidfile _after_ forking ! */
|
/* write pidfile _after_ forking ! */
|
||||||
if (daemon->runfile)
|
if (daemon->runfile)
|
||||||
{
|
{
|
||||||
FILE *pidfile;
|
int fd, err = 0;
|
||||||
|
|
||||||
|
sprintf(daemon->namebuff, "%d\n", (int) getpid());
|
||||||
|
|
||||||
|
/* Explanation: Some installations of dnsmasq (eg Debian/Ubuntu) locate the pid-file
|
||||||
|
in a directory which is writable by the non-privileged user that dnsmasq runs as. This
|
||||||
|
allows the daemon to delete the file as part of its shutdown. This is a security hole to the
|
||||||
|
extent that an attacker running as the unprivileged user could replace the pidfile with a
|
||||||
|
symlink, and have the target of that symlink overwritten as root next time dnsmasq starts.
|
||||||
|
|
||||||
|
The folowing code first deletes any existing file, and then opens it with the O_EXCL flag,
|
||||||
|
ensuring that the open() fails should there be any existing file (because the unlink() failed,
|
||||||
|
or an attacker exploited the race between unlink() and open()). This ensures that no symlink
|
||||||
|
attack can succeed.
|
||||||
|
|
||||||
|
Any compromise of the non-privileged user still theoretically allows the pid-file to be
|
||||||
|
replaced whilst dnsmasq is running. The worst that could allow is that the usual
|
||||||
|
"shutdown dnsmasq" shell command could be tricked into stopping any other process.
|
||||||
|
|
||||||
|
Note that if dnsmasq is started as non-root (eg for testing) it silently ignores
|
||||||
|
failure to write the pid-file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
unlink(daemon->runfile);
|
||||||
|
|
||||||
/* only complain if started as root */
|
if ((fd = open(daemon->runfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)) == -1)
|
||||||
if ((pidfile = fopen(daemon->runfile, "w")))
|
|
||||||
{
|
{
|
||||||
fprintf(pidfile, "%d\n", (int) getpid());
|
/* only complain if started as root */
|
||||||
fclose(pidfile);
|
if (getuid() == 0)
|
||||||
|
err = 1;
|
||||||
}
|
}
|
||||||
else if (getuid() == 0)
|
else
|
||||||
|
{
|
||||||
|
if (!read_write(fd, (unsigned char *)daemon->namebuff, strlen(daemon->namebuff), 0))
|
||||||
|
err = 1;
|
||||||
|
|
||||||
|
while (!err && close(fd) == -1)
|
||||||
|
if (!retry_send())
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err)
|
||||||
{
|
{
|
||||||
send_event(err_pipe[1], EVENT_PIDFILE, errno, daemon->runfile);
|
send_event(err_pipe[1], EVENT_PIDFILE, errno, daemon->runfile);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
@@ -341,7 +463,7 @@ int main (int argc, char **argv)
|
|||||||
/* if we are to run scripts, we need to fork a helper before dropping root. */
|
/* if we are to run scripts, we need to fork a helper before dropping root. */
|
||||||
daemon->helperfd = -1;
|
daemon->helperfd = -1;
|
||||||
#ifdef HAVE_SCRIPT
|
#ifdef HAVE_SCRIPT
|
||||||
if (daemon->dhcp && (daemon->lease_change_command || daemon->luascript))
|
if ((daemon->dhcp || daemon->dhcp6) && (daemon->lease_change_command || daemon->luascript))
|
||||||
daemon->helperfd = create_helper(pipewrite, err_pipe[1], script_uid, script_gid, max_fd);
|
daemon->helperfd = create_helper(pipewrite, err_pipe[1], script_uid, script_gid, max_fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -364,8 +486,9 @@ int main (int argc, char **argv)
|
|||||||
#if defined(HAVE_LINUX_NETWORK)
|
#if defined(HAVE_LINUX_NETWORK)
|
||||||
/* On linux, we keep CAP_NETADMIN (for ARP-injection) and
|
/* On linux, we keep CAP_NETADMIN (for ARP-injection) and
|
||||||
CAP_NET_RAW (for icmp) if we're doing dhcp. If we have yet to bind
|
CAP_NET_RAW (for icmp) if we're doing dhcp. If we have yet to bind
|
||||||
ports because of DAD, we need CAP_NET_BIND_SERVICE too. */
|
ports because of DAD, or we're doing it dynamically,
|
||||||
if (is_dad_listeners())
|
we need CAP_NET_BIND_SERVICE too. */
|
||||||
|
if (is_dad_listeners() || option_bool(OPT_CLEVERBIND))
|
||||||
data->effective = data->permitted = data->inheritable =
|
data->effective = data->permitted = data->inheritable =
|
||||||
(1 << CAP_NET_ADMIN) | (1 << CAP_NET_RAW) |
|
(1 << CAP_NET_ADMIN) | (1 << CAP_NET_RAW) |
|
||||||
(1 << CAP_SETUID) | (1 << CAP_NET_BIND_SERVICE);
|
(1 << CAP_SETUID) | (1 << CAP_NET_BIND_SERVICE);
|
||||||
@@ -413,7 +536,7 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
if (is_dad_listeners())
|
if (is_dad_listeners() || option_bool(OPT_CLEVERBIND))
|
||||||
data->effective = data->permitted =
|
data->effective = data->permitted =
|
||||||
(1 << CAP_NET_ADMIN) | (1 << CAP_NET_RAW) | (1 << CAP_NET_BIND_SERVICE);
|
(1 << CAP_NET_ADMIN) | (1 << CAP_NET_RAW) | (1 << CAP_NET_BIND_SERVICE);
|
||||||
else
|
else
|
||||||
@@ -437,6 +560,34 @@ int main (int argc, char **argv)
|
|||||||
prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
|
prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_TFTP
|
||||||
|
if (option_bool(OPT_TFTP))
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
struct tftp_prefix *p;
|
||||||
|
|
||||||
|
if (daemon->tftp_prefix)
|
||||||
|
{
|
||||||
|
if (!((dir = opendir(daemon->tftp_prefix))))
|
||||||
|
{
|
||||||
|
send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (p = daemon->if_prefix; p; p = p->next)
|
||||||
|
{
|
||||||
|
if (!((dir = opendir(p->prefix))))
|
||||||
|
{
|
||||||
|
send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (daemon->port == 0)
|
if (daemon->port == 0)
|
||||||
my_syslog(LOG_INFO, _("started, version %s DNS disabled"), VERSION);
|
my_syslog(LOG_INFO, _("started, version %s DNS disabled"), VERSION);
|
||||||
else if (daemon->cachesize != 0)
|
else if (daemon->cachesize != 0)
|
||||||
@@ -479,29 +630,30 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (daemon->max_logs != 0)
|
if (daemon->max_logs != 0)
|
||||||
my_syslog(LOG_INFO, _("asynchronous logging enabled, queue limit is %d messages"), daemon->max_logs);
|
my_syslog(LOG_INFO, _("asynchronous logging enabled, queue limit is %d messages"), daemon->max_logs);
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (daemon->dhcp)
|
for (context = daemon->dhcp; context; context = context->next)
|
||||||
{
|
log_context(AF_INET, context);
|
||||||
struct dhcp_context *dhcp_tmp;
|
|
||||||
|
# ifdef HAVE_DHCP6
|
||||||
for (dhcp_tmp = daemon->dhcp; dhcp_tmp; dhcp_tmp = dhcp_tmp->next)
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
{
|
log_context(AF_INET6, context);
|
||||||
prettyprint_time(daemon->dhcp_buff2, dhcp_tmp->lease_time);
|
|
||||||
strcpy(daemon->dhcp_buff, inet_ntoa(dhcp_tmp->start));
|
if (daemon->doing_dhcp6 || daemon->doing_ra)
|
||||||
my_syslog(MS_DHCP | LOG_INFO,
|
dhcp_construct_contexts(now);
|
||||||
(dhcp_tmp->flags & CONTEXT_STATIC) ?
|
|
||||||
_("DHCP, static leases only on %.0s%s, lease time %s") :
|
if (option_bool(OPT_RA))
|
||||||
(dhcp_tmp->flags & CONTEXT_PROXY) ?
|
my_syslog(MS_DHCP | LOG_INFO, _("IPv6 router advertisement enabled"));
|
||||||
_("DHCP, proxy on subnet %.0s%s%.0s") :
|
# endif
|
||||||
_("DHCP, IP range %s -- %s, lease time %s"),
|
|
||||||
daemon->dhcp_buff, inet_ntoa(dhcp_tmp->end), daemon->dhcp_buff2);
|
/* after dhcp_contruct_contexts */
|
||||||
}
|
if (daemon->dhcp || daemon->doing_dhcp6)
|
||||||
}
|
lease_find_interfaces(now);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TFTP
|
#ifdef HAVE_TFTP
|
||||||
if (daemon->tftp_unlimited || daemon->tftp_interfaces)
|
if (option_bool(OPT_TFTP))
|
||||||
{
|
{
|
||||||
#ifdef FD_SETSIZE
|
#ifdef FD_SETSIZE
|
||||||
if (FD_SETSIZE < (unsigned)max_fd)
|
if (FD_SETSIZE < (unsigned)max_fd)
|
||||||
@@ -604,6 +756,20 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_dhcp6)
|
||||||
|
{
|
||||||
|
FD_SET(daemon->dhcp6fd, &rset);
|
||||||
|
bump_maxfd(daemon->dhcp6fd, &maxfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (daemon->doing_ra)
|
||||||
|
{
|
||||||
|
FD_SET(daemon->icmp6fd, &rset);
|
||||||
|
bump_maxfd(daemon->icmp6fd, &maxfd);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
FD_SET(daemon->netlinkfd, &rset);
|
FD_SET(daemon->netlinkfd, &rset);
|
||||||
bump_maxfd(daemon->netlinkfd, &maxfd);
|
bump_maxfd(daemon->netlinkfd, &maxfd);
|
||||||
@@ -616,6 +782,10 @@ int main (int argc, char **argv)
|
|||||||
# ifdef HAVE_SCRIPT
|
# ifdef HAVE_SCRIPT
|
||||||
while (helper_buf_empty() && do_script_run(now));
|
while (helper_buf_empty() && do_script_run(now));
|
||||||
|
|
||||||
|
# ifdef HAVE_TFTP
|
||||||
|
while (helper_buf_empty() && do_tftp_script_run());
|
||||||
|
# endif
|
||||||
|
|
||||||
if (!helper_buf_empty())
|
if (!helper_buf_empty())
|
||||||
{
|
{
|
||||||
FD_SET(daemon->helperfd, &wset);
|
FD_SET(daemon->helperfd, &wset);
|
||||||
@@ -624,6 +794,11 @@ int main (int argc, char **argv)
|
|||||||
# else
|
# else
|
||||||
/* need this for other side-effects */
|
/* need this for other side-effects */
|
||||||
while (do_script_run(now));
|
while (do_script_run(now));
|
||||||
|
|
||||||
|
# ifdef HAVE_TFTP
|
||||||
|
while (do_tftp_script_run());
|
||||||
|
# endif
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -652,7 +827,7 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
if (FD_ISSET(daemon->netlinkfd, &rset))
|
if (FD_ISSET(daemon->netlinkfd, &rset))
|
||||||
netlink_multicast();
|
netlink_multicast(now);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Check for changes to resolv files once per second max. */
|
/* Check for changes to resolv files once per second max. */
|
||||||
@@ -699,6 +874,14 @@ int main (int argc, char **argv)
|
|||||||
dhcp_packet(now, 1);
|
dhcp_packet(now, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_dhcp6 && FD_ISSET(daemon->dhcp6fd, &rset))
|
||||||
|
dhcp6_packet(now);
|
||||||
|
|
||||||
|
if (daemon->doing_ra && FD_ISSET(daemon->icmp6fd, &rset))
|
||||||
|
icmp6_packet(now);
|
||||||
|
#endif
|
||||||
|
|
||||||
# ifdef HAVE_SCRIPT
|
# ifdef HAVE_SCRIPT
|
||||||
if (daemon->helperfd != -1 && FD_ISSET(daemon->helperfd, &wset))
|
if (daemon->helperfd != -1 && FD_ISSET(daemon->helperfd, &wset))
|
||||||
helper_write();
|
helper_write();
|
||||||
@@ -748,6 +931,19 @@ static void sig_handler(int sig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* now == 0 -> queue immediate callback */
|
||||||
|
void send_alarm(time_t event, time_t now)
|
||||||
|
{
|
||||||
|
if (now == 0 || event != 0)
|
||||||
|
{
|
||||||
|
/* alarm(0) or alarm(-ve) doesn't do what we want.... */
|
||||||
|
if ((now == 0 || difftime(event, now) <= 0.0))
|
||||||
|
send_event(pipewrite, EVENT_ALARM, 0, NULL);
|
||||||
|
else
|
||||||
|
alarm((unsigned)difftime(event, now));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void send_event(int fd, int event, int data, char *msg)
|
void send_event(int fd, int event, int data, char *msg)
|
||||||
{
|
{
|
||||||
struct event_desc ev;
|
struct event_desc ev;
|
||||||
@@ -825,6 +1021,9 @@ static void fatal_event(struct event_desc *ev, char *msg)
|
|||||||
|
|
||||||
case EVENT_LUA_ERR:
|
case EVENT_LUA_ERR:
|
||||||
die(_("failed to load Lua script: %s"), msg, EC_MISC);
|
die(_("failed to load Lua script: %s"), msg, EC_MISC);
|
||||||
|
|
||||||
|
case EVENT_TFTP_ERR:
|
||||||
|
die(_("TFTP directory %s inaccessible: %s"), msg, EC_FILE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -860,11 +1059,16 @@ static void async_event(int pipe, time_t now)
|
|||||||
|
|
||||||
case EVENT_ALARM:
|
case EVENT_ALARM:
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (daemon->dhcp)
|
if (daemon->dhcp || daemon->doing_dhcp6)
|
||||||
{
|
{
|
||||||
lease_prune(NULL, now);
|
lease_prune(NULL, now);
|
||||||
lease_update_file(now);
|
lease_update_file(now);
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
else if (daemon->doing_ra)
|
||||||
|
/* Not doing DHCP, so no lease system, manage alarms for ra only */
|
||||||
|
send_alarm(periodic_ra(now), now);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1018,17 +1222,22 @@ void clear_cache_and_reload(time_t now)
|
|||||||
cache_reload();
|
cache_reload();
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (daemon->dhcp)
|
if (daemon->dhcp || daemon->doing_dhcp6)
|
||||||
{
|
{
|
||||||
if (option_bool(OPT_ETHERS))
|
if (option_bool(OPT_ETHERS))
|
||||||
dhcp_read_ethers();
|
dhcp_read_ethers();
|
||||||
reread_dhcp();
|
reread_dhcp();
|
||||||
dhcp_update_configs(daemon->dhcp_conf);
|
dhcp_update_configs(daemon->dhcp_conf);
|
||||||
check_dhcp_hosts(0);
|
|
||||||
lease_update_from_configs();
|
lease_update_from_configs();
|
||||||
lease_update_file(now);
|
lease_update_file(now);
|
||||||
lease_update_dns();
|
lease_update_dns(1);
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
else if (daemon->doing_ra)
|
||||||
|
/* Not doing DHCP, so no lease system, manage
|
||||||
|
alarms for ra only */
|
||||||
|
send_alarm(periodic_ra(now), now);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1131,18 +1340,19 @@ static void check_dns_listeners(fd_set *set, time_t now)
|
|||||||
int confd;
|
int confd;
|
||||||
struct irec *iface = NULL;
|
struct irec *iface = NULL;
|
||||||
pid_t p;
|
pid_t p;
|
||||||
|
union mysockaddr tcp_addr;
|
||||||
|
socklen_t tcp_len = sizeof(union mysockaddr);
|
||||||
|
|
||||||
|
while ((confd = accept(listener->tcpfd, NULL, NULL)) == -1 && errno == EINTR);
|
||||||
|
|
||||||
while((confd = accept(listener->tcpfd, NULL, NULL)) == -1 && errno == EINTR);
|
if (confd == -1 ||
|
||||||
|
getsockname(confd, (struct sockaddr *)&tcp_addr, &tcp_len) == -1)
|
||||||
if (confd == -1)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (option_bool(OPT_NOWILD))
|
if (option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND))
|
||||||
iface = listener->iface;
|
iface = listener->iface; /* May be NULL */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
union mysockaddr tcp_addr;
|
|
||||||
socklen_t tcp_len = sizeof(union mysockaddr);
|
|
||||||
/* Check for allowed interfaces when binding the wildcard address:
|
/* Check for allowed interfaces when binding the wildcard address:
|
||||||
we do this by looking for an interface with the same address as
|
we do this by looking for an interface with the same address as
|
||||||
the local address of the TCP connection, then looking to see if that's
|
the local address of the TCP connection, then looking to see if that's
|
||||||
@@ -1150,14 +1360,13 @@ static void check_dns_listeners(fd_set *set, time_t now)
|
|||||||
interface too, for localisation. */
|
interface too, for localisation. */
|
||||||
|
|
||||||
/* interface may be new since startup */
|
/* interface may be new since startup */
|
||||||
if (enumerate_interfaces() &&
|
if (enumerate_interfaces())
|
||||||
getsockname(confd, (struct sockaddr *)&tcp_addr, &tcp_len) != -1)
|
|
||||||
for (iface = daemon->interfaces; iface; iface = iface->next)
|
for (iface = daemon->interfaces; iface; iface = iface->next)
|
||||||
if (sockaddr_isequal(&iface->addr, &tcp_addr))
|
if (sockaddr_isequal(&iface->addr, &tcp_addr))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iface)
|
if (!iface && !(option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND)))
|
||||||
{
|
{
|
||||||
shutdown(confd, SHUT_RDWR);
|
shutdown(confd, SHUT_RDWR);
|
||||||
close(confd);
|
close(confd);
|
||||||
@@ -1183,7 +1392,20 @@ static void check_dns_listeners(fd_set *set, time_t now)
|
|||||||
unsigned char *buff;
|
unsigned char *buff;
|
||||||
struct server *s;
|
struct server *s;
|
||||||
int flags;
|
int flags;
|
||||||
|
struct in_addr netmask;
|
||||||
|
int auth_dns;
|
||||||
|
|
||||||
|
if (iface)
|
||||||
|
{
|
||||||
|
netmask = iface->netmask;
|
||||||
|
auth_dns = iface->dns_auth;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
netmask.s_addr = 0;
|
||||||
|
auth_dns = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NO_FORK
|
#ifndef NO_FORK
|
||||||
/* Arrange for SIGALARM after CHILD_LIFETIME seconds to
|
/* Arrange for SIGALARM after CHILD_LIFETIME seconds to
|
||||||
terminate the process. */
|
terminate the process. */
|
||||||
@@ -1201,7 +1423,7 @@ static void check_dns_listeners(fd_set *set, time_t now)
|
|||||||
if ((flags = fcntl(confd, F_GETFL, 0)) != -1)
|
if ((flags = fcntl(confd, F_GETFL, 0)) != -1)
|
||||||
fcntl(confd, F_SETFL, flags & ~O_NONBLOCK);
|
fcntl(confd, F_SETFL, flags & ~O_NONBLOCK);
|
||||||
|
|
||||||
buff = tcp_request(confd, now, &iface->addr, iface->netmask);
|
buff = tcp_request(confd, now, &tcp_addr, netmask, auth_dns);
|
||||||
|
|
||||||
shutdown(confd, SHUT_RDWR);
|
shutdown(confd, SHUT_RDWR);
|
||||||
close(confd);
|
close(confd);
|
||||||
@@ -1312,7 +1534,15 @@ int icmp_ping(struct in_addr addr)
|
|||||||
FD_SET(fd, &rset);
|
FD_SET(fd, &rset);
|
||||||
set_dns_listeners(now, &rset, &maxfd);
|
set_dns_listeners(now, &rset, &maxfd);
|
||||||
set_log_writer(&wset, &maxfd);
|
set_log_writer(&wset, &maxfd);
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_ra)
|
||||||
|
{
|
||||||
|
FD_SET(daemon->icmp6fd, &rset);
|
||||||
|
bump_maxfd(daemon->icmp6fd, &maxfd);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (select(maxfd+1, &rset, &wset, NULL, &tv) < 0)
|
if (select(maxfd+1, &rset, &wset, NULL, &tv) < 0)
|
||||||
{
|
{
|
||||||
FD_ZERO(&rset);
|
FD_ZERO(&rset);
|
||||||
@@ -1324,6 +1554,11 @@ int icmp_ping(struct in_addr addr)
|
|||||||
check_log_writer(&wset);
|
check_log_writer(&wset);
|
||||||
check_dns_listeners(&rset, now);
|
check_dns_listeners(&rset, now);
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_ra && FD_ISSET(daemon->icmp6fd, &rset))
|
||||||
|
icmp6_packet(now);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TFTP
|
#ifdef HAVE_TFTP
|
||||||
check_tftp_listeners(&rset, now);
|
check_tftp_listeners(&rset, now);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+281
-64
@@ -54,11 +54,13 @@
|
|||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
typedef unsigned short u16;
|
typedef unsigned short u16;
|
||||||
typedef unsigned int u32;
|
typedef unsigned int u32;
|
||||||
|
typedef unsigned long long u64;
|
||||||
|
|
||||||
#include "dns_protocol.h"
|
#include "dns-protocol.h"
|
||||||
#include "dhcp_protocol.h"
|
#include "dhcp-protocol.h"
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
#include "dhcp6_protocol.h"
|
#include "dhcp6-protocol.h"
|
||||||
|
#include "radv-protocol.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define gettext_noop(S) (S)
|
#define gettext_noop(S) (S)
|
||||||
@@ -157,6 +159,7 @@ struct event_desc {
|
|||||||
#define EVENT_LOG_ERR 17
|
#define EVENT_LOG_ERR 17
|
||||||
#define EVENT_FORK_ERR 18
|
#define EVENT_FORK_ERR 18
|
||||||
#define EVENT_LUA_ERR 19
|
#define EVENT_LUA_ERR 19
|
||||||
|
#define EVENT_TFTP_ERR 20
|
||||||
|
|
||||||
/* Exit codes. */
|
/* Exit codes. */
|
||||||
#define EC_GOOD 0
|
#define EC_GOOD 0
|
||||||
@@ -214,7 +217,11 @@ struct event_desc {
|
|||||||
#define OPT_CONSEC_ADDR 34
|
#define OPT_CONSEC_ADDR 34
|
||||||
#define OPT_CONNTRACK 35
|
#define OPT_CONNTRACK 35
|
||||||
#define OPT_FQDN_UPDATE 36
|
#define OPT_FQDN_UPDATE 36
|
||||||
#define OPT_LAST 37
|
#define OPT_RA 37
|
||||||
|
#define OPT_TFTP_LC 38
|
||||||
|
#define OPT_CLEVERBIND 39
|
||||||
|
#define OPT_TFTP 40
|
||||||
|
#define OPT_LAST 41
|
||||||
|
|
||||||
/* extra flags for my_syslog, we use a couple of facilities since they are known
|
/* extra flags for my_syslog, we use a couple of facilities since they are known
|
||||||
not to occupy the same bits as priorities, no matter how syslog.h is set up. */
|
not to occupy the same bits as priorities, no matter how syslog.h is set up. */
|
||||||
@@ -271,6 +278,32 @@ struct cname {
|
|||||||
struct cname *next;
|
struct cname *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct auth_zone {
|
||||||
|
char *domain;
|
||||||
|
struct subnet {
|
||||||
|
int is6, prefixlen;
|
||||||
|
struct in_addr addr4;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
struct in6_addr addr6;
|
||||||
|
#endif
|
||||||
|
struct subnet *next;
|
||||||
|
} *subnet;
|
||||||
|
struct auth_zone *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct host_record {
|
||||||
|
struct name_list {
|
||||||
|
char *name;
|
||||||
|
struct name_list *next;
|
||||||
|
} *names;
|
||||||
|
struct in_addr addr;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
struct in6_addr addr6;
|
||||||
|
#endif
|
||||||
|
struct host_record *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct interface_name {
|
struct interface_name {
|
||||||
char *name; /* domain name */
|
char *name; /* domain name */
|
||||||
char *intr; /* interface name */
|
char *intr; /* interface name */
|
||||||
@@ -282,17 +315,30 @@ union bigname {
|
|||||||
union bigname *next; /* freelist */
|
union bigname *next; /* freelist */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct keydata {
|
||||||
|
struct keydata *next;
|
||||||
|
unsigned char key[KEYBLOCK_LEN];
|
||||||
|
};
|
||||||
|
|
||||||
struct crec {
|
struct crec {
|
||||||
struct crec *next, *prev, *hash_next;
|
struct crec *next, *prev, *hash_next;
|
||||||
time_t ttd; /* time to die */
|
/* union is 16 bytes when doing IPv6, 8 bytes on 32 bit machines without IPv6 */
|
||||||
int uid;
|
|
||||||
union {
|
union {
|
||||||
struct all_addr addr;
|
struct all_addr addr;
|
||||||
struct {
|
struct {
|
||||||
struct crec *cache;
|
struct crec *cache;
|
||||||
int uid;
|
int uid;
|
||||||
} cname;
|
} cname;
|
||||||
|
struct {
|
||||||
|
struct keydata *keydata;
|
||||||
|
unsigned char algo;
|
||||||
|
unsigned char digest; /* DS only */
|
||||||
|
unsigned short flags_or_keyid; /* flags for DNSKEY, keyid for DS */
|
||||||
|
} key;
|
||||||
} addr;
|
} addr;
|
||||||
|
time_t ttd; /* time to die */
|
||||||
|
/* used as keylen if F_DS or F_DNSKEY, index to source for F_HOSTS */
|
||||||
|
int uid;
|
||||||
unsigned short flags;
|
unsigned short flags;
|
||||||
union {
|
union {
|
||||||
char sname[SMALLDNAME];
|
char sname[SMALLDNAME];
|
||||||
@@ -313,14 +359,23 @@ struct crec {
|
|||||||
#define F_BIGNAME (1u<<9)
|
#define F_BIGNAME (1u<<9)
|
||||||
#define F_NXDOMAIN (1u<<10)
|
#define F_NXDOMAIN (1u<<10)
|
||||||
#define F_CNAME (1u<<11)
|
#define F_CNAME (1u<<11)
|
||||||
#define F_NOERR (1u<<12)
|
#define F_DNSKEY (1u<<12)
|
||||||
#define F_CONFIG (1u<<13)
|
#define F_CONFIG (1u<<13)
|
||||||
|
#define F_DS (1u<<14)
|
||||||
|
#define F_DNSSECOK (1u<<15)
|
||||||
|
|
||||||
/* below here are only valid as args to log_query: cache
|
/* below here are only valid as args to log_query: cache
|
||||||
entries are limited to 16 bits */
|
entries are limited to 16 bits */
|
||||||
#define F_UPSTREAM (1u<<16)
|
#define F_UPSTREAM (1u<<16)
|
||||||
#define F_RRNAME (1u<<17)
|
#define F_RRNAME (1u<<17)
|
||||||
#define F_SERVER (1u<<18)
|
#define F_SERVER (1u<<18)
|
||||||
#define F_QUERY (1u<<19)
|
#define F_QUERY (1u<<19)
|
||||||
|
#define F_NOERR (1u<<20)
|
||||||
|
#define F_AUTH (1u<<21)
|
||||||
|
|
||||||
|
/* composites */
|
||||||
|
#define F_TYPE (F_IPV4 | F_IPV6 | F_DNSKEY | F_DS) /* Only one may be set */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* struct sockaddr is not large enough to hold any address,
|
/* struct sockaddr is not large enough to hold any address,
|
||||||
@@ -373,14 +428,14 @@ struct server {
|
|||||||
struct irec {
|
struct irec {
|
||||||
union mysockaddr addr;
|
union mysockaddr addr;
|
||||||
struct in_addr netmask; /* only valid for IPv4 */
|
struct in_addr netmask; /* only valid for IPv4 */
|
||||||
int tftp_ok, mtu, done, dad;
|
int tftp_ok, dhcp_ok, mtu, done, dad, dns_auth;
|
||||||
char *name;
|
char *name;
|
||||||
struct irec *next;
|
struct irec *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct listener {
|
struct listener {
|
||||||
int fd, tcpfd, tftpfd, family;
|
int fd, tcpfd, tftpfd, family;
|
||||||
struct irec *iface; /* only valid for non-wildcard */
|
struct irec *iface; /* only sometimes valid for non-wildcard */
|
||||||
struct listener *next;
|
struct listener *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -388,7 +443,7 @@ struct listener {
|
|||||||
struct iname {
|
struct iname {
|
||||||
char *name;
|
char *name;
|
||||||
union mysockaddr addr;
|
union mysockaddr addr;
|
||||||
int isloop, used;
|
int used;
|
||||||
struct iname *next;
|
struct iname *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -429,33 +484,54 @@ struct frec {
|
|||||||
struct frec *next;
|
struct frec *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* flags in top of length field for DHCP-option tables */
|
||||||
|
#define OT_ADDR_LIST 0x8000
|
||||||
|
#define OT_RFC1035_NAME 0x4000
|
||||||
|
#define OT_INTERNAL 0x2000
|
||||||
|
#define OT_NAME 0x1000
|
||||||
|
#define OT_CSTRING 0x0800
|
||||||
|
#define OT_DEC 0x0400
|
||||||
|
#define OT_TIME 0x0200
|
||||||
|
|
||||||
/* actions in the daemon->helper RPC */
|
/* actions in the daemon->helper RPC */
|
||||||
#define ACTION_DEL 1
|
#define ACTION_DEL 1
|
||||||
#define ACTION_OLD_HOSTNAME 2
|
#define ACTION_OLD_HOSTNAME 2
|
||||||
#define ACTION_OLD 3
|
#define ACTION_OLD 3
|
||||||
#define ACTION_ADD 4
|
#define ACTION_ADD 4
|
||||||
|
#define ACTION_TFTP 5
|
||||||
|
|
||||||
|
#define LEASE_NEW 1 /* newly created */
|
||||||
|
#define LEASE_CHANGED 2 /* modified */
|
||||||
|
#define LEASE_AUX_CHANGED 4 /* CLID or expiry changed */
|
||||||
|
#define LEASE_AUTH_NAME 8 /* hostname came from config, not from client */
|
||||||
|
#define LEASE_USED 16 /* used this DHCPv6 transaction */
|
||||||
|
#define LEASE_NA 32 /* IPv6 no-temporary lease */
|
||||||
|
#define LEASE_TA 64 /* IPv6 temporary lease */
|
||||||
|
#define LEASE_HAVE_HWADDR 128 /* Have set hwaddress */
|
||||||
|
|
||||||
struct dhcp_lease {
|
struct dhcp_lease {
|
||||||
int clid_len; /* length of client identifier */
|
int clid_len; /* length of client identifier */
|
||||||
unsigned char *clid; /* clientid */
|
unsigned char *clid; /* clientid */
|
||||||
char *hostname, *fqdn; /* name from client-hostname option or config */
|
char *hostname, *fqdn; /* name from client-hostname option or config */
|
||||||
char *old_hostname; /* hostname before it moved to another lease */
|
char *old_hostname; /* hostname before it moved to another lease */
|
||||||
char auth_name; /* hostname came from config, not from client */
|
int flags;
|
||||||
char new; /* newly created */
|
|
||||||
char changed; /* modified */
|
|
||||||
char aux_changed; /* CLID or expiry changed */
|
|
||||||
time_t expires; /* lease expiry */
|
time_t expires; /* lease expiry */
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
#endif
|
#endif
|
||||||
int hwaddr_len, hwaddr_type;
|
int hwaddr_len, hwaddr_type; /* hw_type used for iaid in v6 */
|
||||||
unsigned char hwaddr[DHCP_CHADDR_MAX];
|
unsigned char hwaddr[DHCP_CHADDR_MAX]; /* also IPv6 address */
|
||||||
struct in_addr addr, override, giaddr;
|
struct in_addr addr, override, giaddr;
|
||||||
unsigned char *extradata;
|
unsigned char *extradata;
|
||||||
unsigned int extradata_len, extradata_size;
|
unsigned int extradata_len, extradata_size;
|
||||||
int last_interface;
|
int last_interface;
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
char is_ipv6;
|
struct slaac_address {
|
||||||
|
struct in6_addr addr, local;
|
||||||
|
time_t ping_time;
|
||||||
|
int backoff; /* zero -> confirmed */
|
||||||
|
struct slaac_address *next;
|
||||||
|
} *slaac_address;
|
||||||
#endif
|
#endif
|
||||||
struct dhcp_lease *next;
|
struct dhcp_lease *next;
|
||||||
};
|
};
|
||||||
@@ -489,6 +565,9 @@ struct dhcp_config {
|
|||||||
unsigned char *clid; /* clientid */
|
unsigned char *clid; /* clientid */
|
||||||
char *hostname, *domain;
|
char *hostname, *domain;
|
||||||
struct dhcp_netid_list *netid;
|
struct dhcp_netid_list *netid;
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
struct in6_addr addr6;
|
||||||
|
#endif
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
time_t decline_time;
|
time_t decline_time;
|
||||||
unsigned int lease_time;
|
unsigned int lease_time;
|
||||||
@@ -496,6 +575,8 @@ struct dhcp_config {
|
|||||||
struct dhcp_config *next;
|
struct dhcp_config *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define have_config(config, mask) ((config) && ((config)->flags & (mask)))
|
||||||
|
|
||||||
#define CONFIG_DISABLE 1
|
#define CONFIG_DISABLE 1
|
||||||
#define CONFIG_CLID 2
|
#define CONFIG_CLID 2
|
||||||
#define CONFIG_TIME 8
|
#define CONFIG_TIME 8
|
||||||
@@ -506,6 +587,7 @@ struct dhcp_config {
|
|||||||
#define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */
|
#define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */
|
||||||
#define CONFIG_DECLINED 1024 /* address declined by client */
|
#define CONFIG_DECLINED 1024 /* address declined by client */
|
||||||
#define CONFIG_BANK 2048 /* from dhcp hosts file */
|
#define CONFIG_BANK 2048 /* from dhcp hosts file */
|
||||||
|
#define CONFIG_ADDR6 4096
|
||||||
|
|
||||||
struct dhcp_opt {
|
struct dhcp_opt {
|
||||||
int opt, len, flags;
|
int opt, len, flags;
|
||||||
@@ -532,6 +614,7 @@ struct dhcp_opt {
|
|||||||
#define DHOPT_VENDOR_MATCH 1024
|
#define DHOPT_VENDOR_MATCH 1024
|
||||||
#define DHOPT_RFC3925 2048
|
#define DHOPT_RFC3925 2048
|
||||||
#define DHOPT_TAGOK 4096
|
#define DHOPT_TAGOK 4096
|
||||||
|
#define DHOPT_ADDR6 8192
|
||||||
|
|
||||||
struct dhcp_boot {
|
struct dhcp_boot {
|
||||||
char *file, *sname, *tftp_sname;
|
char *file, *sname, *tftp_sname;
|
||||||
@@ -542,7 +625,7 @@ struct dhcp_boot {
|
|||||||
|
|
||||||
struct pxe_service {
|
struct pxe_service {
|
||||||
unsigned short CSA, type;
|
unsigned short CSA, type;
|
||||||
char *menu, *basename;
|
char *menu, *basename, *sname;
|
||||||
struct in_addr server;
|
struct in_addr server;
|
||||||
struct dhcp_netid *netid;
|
struct dhcp_netid *netid;
|
||||||
struct pxe_service *next;
|
struct pxe_service *next;
|
||||||
@@ -556,7 +639,8 @@ struct pxe_service {
|
|||||||
|
|
||||||
/* vendorclass, userclass, remote-id or cicuit-id */
|
/* vendorclass, userclass, remote-id or cicuit-id */
|
||||||
struct dhcp_vendor {
|
struct dhcp_vendor {
|
||||||
int len, match_type, option;
|
int len, match_type;
|
||||||
|
unsigned int enterprise;
|
||||||
char *data;
|
char *data;
|
||||||
struct dhcp_netid netid;
|
struct dhcp_netid netid;
|
||||||
struct dhcp_vendor *next;
|
struct dhcp_vendor *next;
|
||||||
@@ -578,8 +662,12 @@ struct dhcp_bridge {
|
|||||||
struct cond_domain {
|
struct cond_domain {
|
||||||
char *domain;
|
char *domain;
|
||||||
struct in_addr start, end;
|
struct in_addr start, end;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
struct in6_addr start6, end6;
|
||||||
|
#endif
|
||||||
|
int is6;
|
||||||
struct cond_domain *next;
|
struct cond_domain *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dhcp_context {
|
struct dhcp_context {
|
||||||
unsigned int lease_time, addr_epoch;
|
unsigned int lease_time, addr_epoch;
|
||||||
@@ -588,19 +676,32 @@ struct dhcp_context {
|
|||||||
struct in_addr start, end; /* range of available addresses */
|
struct in_addr start, end; /* range of available addresses */
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
struct in6_addr start6, end6; /* range of available addresses */
|
struct in6_addr start6, end6; /* range of available addresses */
|
||||||
int prefix;
|
struct in6_addr local6;
|
||||||
|
int prefix, if_index;
|
||||||
|
time_t ra_time, ra_short_period_start;
|
||||||
|
char *template_interface;
|
||||||
|
int valid, preferred; /* times from address for constructed contexts */
|
||||||
#endif
|
#endif
|
||||||
int flags;
|
int flags;
|
||||||
char *interface;
|
|
||||||
struct dhcp_netid netid, *filter;
|
struct dhcp_netid netid, *filter;
|
||||||
struct dhcp_context *next, *current;
|
struct dhcp_context *next, *current;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CONTEXT_STATIC 1
|
#define CONTEXT_STATIC 1
|
||||||
#define CONTEXT_NETMASK 2
|
#define CONTEXT_NETMASK 2
|
||||||
#define CONTEXT_BRDCAST 4
|
#define CONTEXT_BRDCAST 4
|
||||||
#define CONTEXT_PROXY 8
|
#define CONTEXT_PROXY 8
|
||||||
#define CONTEXT_IPV6 16
|
#define CONTEXT_RA_ONLY 16
|
||||||
|
#define CONTEXT_RA_DONE 32
|
||||||
|
#define CONTEXT_RA_NAME 64
|
||||||
|
#define CONTEXT_RA_STATELESS 128
|
||||||
|
#define CONTEXT_DHCP 256
|
||||||
|
#define CONTEXT_DEPRECATE 512
|
||||||
|
#define CONTEXT_TEMPLATE 1024 /* create contexts using addresses */
|
||||||
|
#define CONTEXT_CONSTRUCTED 2048
|
||||||
|
#define CONTEXT_GC 4096
|
||||||
|
#define CONTEXT_RA 8192
|
||||||
|
|
||||||
|
|
||||||
struct ping_result {
|
struct ping_result {
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
@@ -634,11 +735,6 @@ struct addr_list {
|
|||||||
struct addr_list *next;
|
struct addr_list *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct interface_list {
|
|
||||||
char *interface;
|
|
||||||
struct interface_list *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct tftp_prefix {
|
struct tftp_prefix {
|
||||||
char *interface;
|
char *interface;
|
||||||
char *prefix;
|
char *prefix;
|
||||||
@@ -656,20 +752,25 @@ extern struct daemon {
|
|||||||
time_t last_resolv;
|
time_t last_resolv;
|
||||||
struct mx_srv_record *mxnames;
|
struct mx_srv_record *mxnames;
|
||||||
struct naptr *naptr;
|
struct naptr *naptr;
|
||||||
struct txt_record *txt;
|
struct txt_record *txt, *rr;
|
||||||
struct ptr_record *ptr;
|
struct ptr_record *ptr;
|
||||||
|
struct host_record *host_records, *host_records_tail;
|
||||||
struct cname *cnames;
|
struct cname *cnames;
|
||||||
|
struct auth_zone *auth_zones;
|
||||||
struct interface_name *int_names;
|
struct interface_name *int_names;
|
||||||
char *mxtarget;
|
char *mxtarget;
|
||||||
char *lease_file;
|
char *lease_file;
|
||||||
char *username, *groupname, *scriptuser;
|
char *username, *groupname, *scriptuser;
|
||||||
char *luascript;
|
char *luascript;
|
||||||
|
char *authserver, *hostmaster;
|
||||||
|
struct iname *authinterface;
|
||||||
|
struct name_list *secondary_forward_server;
|
||||||
int group_set, osport;
|
int group_set, osport;
|
||||||
char *domain_suffix;
|
char *domain_suffix;
|
||||||
struct cond_domain *cond_domain;
|
struct cond_domain *cond_domain;
|
||||||
char *runfile;
|
char *runfile;
|
||||||
char *lease_change_command;
|
char *lease_change_command;
|
||||||
struct iname *if_names, *if_addrs, *if_except, *dhcp_except;
|
struct iname *if_names, *if_addrs, *if_except, *dhcp_except, *auth_peers;
|
||||||
struct bogus_addr *bogus_addr;
|
struct bogus_addr *bogus_addr;
|
||||||
struct server *servers;
|
struct server *servers;
|
||||||
int log_fac; /* log facility */
|
int log_fac; /* log facility */
|
||||||
@@ -677,11 +778,11 @@ extern struct daemon {
|
|||||||
int max_logs; /* queue limit */
|
int max_logs; /* queue limit */
|
||||||
int cachesize, ftabsize;
|
int cachesize, ftabsize;
|
||||||
int port, query_port, min_port;
|
int port, query_port, min_port;
|
||||||
unsigned long local_ttl, neg_ttl, max_ttl;
|
unsigned long local_ttl, neg_ttl, max_ttl, max_cache_ttl, auth_ttl;
|
||||||
struct hostsfile *addn_hosts;
|
struct hostsfile *addn_hosts;
|
||||||
struct dhcp_context *dhcp, *dhcp6;
|
struct dhcp_context *dhcp, *dhcp6;
|
||||||
struct dhcp_config *dhcp_conf;
|
struct dhcp_config *dhcp_conf;
|
||||||
struct dhcp_opt *dhcp_opts, *dhcp_match;
|
struct dhcp_opt *dhcp_opts, *dhcp_match, *dhcp_opts6, *dhcp_match6;
|
||||||
struct dhcp_vendor *dhcp_vendors;
|
struct dhcp_vendor *dhcp_vendors;
|
||||||
struct dhcp_mac *dhcp_macs;
|
struct dhcp_mac *dhcp_macs;
|
||||||
struct dhcp_boot *boot_config;
|
struct dhcp_boot *boot_config;
|
||||||
@@ -690,6 +791,7 @@ extern struct daemon {
|
|||||||
struct addr_list *override_relays;
|
struct addr_list *override_relays;
|
||||||
int override;
|
int override;
|
||||||
int enable_pxe;
|
int enable_pxe;
|
||||||
|
int doing_ra, doing_dhcp6;
|
||||||
struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
|
struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
|
||||||
struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
|
struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
|
||||||
struct hostsfile *dhcp_hosts_file, *dhcp_opts_file;
|
struct hostsfile *dhcp_hosts_file, *dhcp_opts_file;
|
||||||
@@ -701,8 +803,10 @@ extern struct daemon {
|
|||||||
unsigned short edns_pktsz;
|
unsigned short edns_pktsz;
|
||||||
char *tftp_prefix;
|
char *tftp_prefix;
|
||||||
struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */
|
struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */
|
||||||
struct interface_list *tftp_interfaces; /* interfaces for limited TFTP service */
|
unsigned int duid_enterprise, duid_config_len;
|
||||||
int tftp_unlimited;
|
unsigned char *duid_config;
|
||||||
|
char *dbus_name;
|
||||||
|
unsigned long soa_sn, soa_refresh, soa_retry, soa_expiry;
|
||||||
|
|
||||||
/* globally used stuff for DNS */
|
/* globally used stuff for DNS */
|
||||||
char *packet; /* packet buffer */
|
char *packet; /* packet buffer */
|
||||||
@@ -739,7 +843,7 @@ extern struct daemon {
|
|||||||
int duid_len;
|
int duid_len;
|
||||||
unsigned char *duid;
|
unsigned char *duid;
|
||||||
struct iovec outpacket;
|
struct iovec outpacket;
|
||||||
int dhcp6fd;
|
int dhcp6fd, icmp6fd;
|
||||||
#endif
|
#endif
|
||||||
/* DBus stuff */
|
/* DBus stuff */
|
||||||
/* void * here to avoid depending on dbus headers outside dbus.c */
|
/* void * here to avoid depending on dbus headers outside dbus.c */
|
||||||
@@ -749,7 +853,7 @@ extern struct daemon {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TFTP stuff */
|
/* TFTP stuff */
|
||||||
struct tftp_transfer *tftp_trans;
|
struct tftp_transfer *tftp_trans, *tftp_done_trans;
|
||||||
|
|
||||||
/* utility string buffer, hold max sized IP address as string */
|
/* utility string buffer, hold max sized IP address as string */
|
||||||
char *addrbuff;
|
char *addrbuff;
|
||||||
@@ -760,7 +864,7 @@ extern struct daemon {
|
|||||||
void cache_init(void);
|
void cache_init(void);
|
||||||
void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg);
|
void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg);
|
||||||
char *record_source(int index);
|
char *record_source(int index);
|
||||||
void querystr(char *str, unsigned short type);
|
void querystr(char *desc, char *str, unsigned short type);
|
||||||
struct crec *cache_find_by_addr(struct crec *crecp,
|
struct crec *cache_find_by_addr(struct crec *crecp,
|
||||||
struct all_addr *addr, time_t now,
|
struct all_addr *addr, time_t now,
|
||||||
unsigned short prot);
|
unsigned short prot);
|
||||||
@@ -771,12 +875,20 @@ void cache_start_insert(void);
|
|||||||
struct crec *cache_insert(char *name, struct all_addr *addr,
|
struct crec *cache_insert(char *name, struct all_addr *addr,
|
||||||
time_t now, unsigned long ttl, unsigned short flags);
|
time_t now, unsigned long ttl, unsigned short flags);
|
||||||
void cache_reload(void);
|
void cache_reload(void);
|
||||||
void cache_add_dhcp_entry(char *host_name, struct in_addr *host_address, time_t ttd);
|
void cache_add_dhcp_entry(char *host_name, int prot, struct all_addr *host_address, time_t ttd);
|
||||||
struct in_addr a_record_from_hosts(char *name, time_t now);
|
struct in_addr a_record_from_hosts(char *name, time_t now);
|
||||||
void cache_unhash_dhcp(void);
|
void cache_unhash_dhcp(void);
|
||||||
void dump_cache(time_t now);
|
void dump_cache(time_t now);
|
||||||
char *cache_get_name(struct crec *crecp);
|
char *cache_get_name(struct crec *crecp);
|
||||||
|
struct crec *cache_enumerate(int init);
|
||||||
char *get_domain(struct in_addr addr);
|
char *get_domain(struct in_addr addr);
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
char *get_domain6(struct in6_addr *addr);
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_DNSSEC
|
||||||
|
struct keydata *keydata_alloc(char *data, size_t len);
|
||||||
|
void keydata_free(struct keydata *blocks);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* rfc1035.c */
|
/* rfc1035.c */
|
||||||
unsigned int extract_request(struct dns_header *header, size_t qlen,
|
unsigned int extract_request(struct dns_header *header, size_t qlen,
|
||||||
@@ -797,6 +909,18 @@ unsigned int questions_crc(struct dns_header *header, size_t plen, char *buff);
|
|||||||
size_t resize_packet(struct dns_header *header, size_t plen,
|
size_t resize_packet(struct dns_header *header, size_t plen,
|
||||||
unsigned char *pheader, size_t hlen);
|
unsigned char *pheader, size_t hlen);
|
||||||
size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3);
|
size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3);
|
||||||
|
int add_resource_record(struct dns_header *header, char *limit, int *truncp,
|
||||||
|
int nameoffset, unsigned char **pp, unsigned long ttl,
|
||||||
|
int *offset, unsigned short type, unsigned short class, char *format, ...);
|
||||||
|
unsigned char *skip_questions(struct dns_header *header, size_t plen);
|
||||||
|
int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
|
||||||
|
char *name, int isExtract, int extrabytes);
|
||||||
|
int in_arpa_name_2_addr(char *namein, struct all_addr *addrp);
|
||||||
|
|
||||||
|
/* auth.c */
|
||||||
|
#ifdef HAVE_AUTH
|
||||||
|
size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, time_t now, union mysockaddr *peer_addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* util.c */
|
/* util.c */
|
||||||
void rand_init(void);
|
void rand_init(void);
|
||||||
@@ -809,11 +933,13 @@ void safe_pipe(int *fd, int read_noblock);
|
|||||||
void *whine_malloc(size_t size);
|
void *whine_malloc(size_t size);
|
||||||
int sa_len(union mysockaddr *addr);
|
int sa_len(union mysockaddr *addr);
|
||||||
int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
|
int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
|
||||||
int hostname_isequal(char *a, char *b);
|
int hostname_isequal(const char *a, const char *b);
|
||||||
time_t dnsmasq_time(void);
|
time_t dnsmasq_time(void);
|
||||||
int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
|
int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
int is_same_net6(struct in6_addr *a, struct in6_addr *b, int prefixlen);
|
int is_same_net6(struct in6_addr *a, struct in6_addr *b, int prefixlen);
|
||||||
|
u64 addr6part(struct in6_addr *addr);
|
||||||
|
void setaddr6part(struct in6_addr *addr, u64 host);
|
||||||
#endif
|
#endif
|
||||||
int retry_send(void);
|
int retry_send(void);
|
||||||
void prettyprint_time(char *buf, unsigned int t);
|
void prettyprint_time(char *buf, unsigned int t);
|
||||||
@@ -838,19 +964,23 @@ void flush_log(void);
|
|||||||
|
|
||||||
/* option.c */
|
/* option.c */
|
||||||
void read_opts (int argc, char **argv, char *compile_opts);
|
void read_opts (int argc, char **argv, char *compile_opts);
|
||||||
char *option_string(unsigned char opt, int *is_ip, int *is_name);
|
char *option_string(int prot, unsigned int opt, unsigned char *val,
|
||||||
|
int opt_len, char *buf, int buf_len);
|
||||||
void reread_dhcp(void);
|
void reread_dhcp(void);
|
||||||
void set_option_bool(unsigned int opt);
|
void set_option_bool(unsigned int opt);
|
||||||
|
void reset_option_bool(unsigned int opt);
|
||||||
struct hostsfile *expand_filelist(struct hostsfile *list);
|
struct hostsfile *expand_filelist(struct hostsfile *list);
|
||||||
|
char *parse_server(char *arg, union mysockaddr *addr,
|
||||||
|
union mysockaddr *source_addr, char *interface, int *flags);
|
||||||
|
|
||||||
/* forward.c */
|
/* forward.c */
|
||||||
void reply_query(int fd, int family, time_t now);
|
void reply_query(int fd, int family, time_t now);
|
||||||
void receive_query(struct listener *listen, time_t now);
|
void receive_query(struct listener *listen, time_t now);
|
||||||
unsigned char *tcp_request(int confd, time_t now,
|
unsigned char *tcp_request(int confd, time_t now,
|
||||||
union mysockaddr *local_addr, struct in_addr netmask);
|
union mysockaddr *local_addr, struct in_addr netmask, int auth_dns);
|
||||||
void server_gone(struct server *server);
|
void server_gone(struct server *server);
|
||||||
struct frec *get_new_frec(time_t now, int *wait);
|
struct frec *get_new_frec(time_t now, int *wait);
|
||||||
void send_from(int fd, int nowild, char *packet, size_t len,
|
int send_from(int fd, int nowild, char *packet, size_t len,
|
||||||
union mysockaddr *to, struct all_addr *source,
|
union mysockaddr *to, struct all_addr *source,
|
||||||
unsigned int iface);
|
unsigned int iface);
|
||||||
|
|
||||||
@@ -865,7 +995,7 @@ int enumerate_interfaces();
|
|||||||
void create_wildcard_listeners(void);
|
void create_wildcard_listeners(void);
|
||||||
void create_bound_listeners(int die);
|
void create_bound_listeners(int die);
|
||||||
int is_dad_listeners(void);
|
int is_dad_listeners(void);
|
||||||
int iface_check(int family, struct all_addr *addr, char *name);
|
int iface_check(int family, struct all_addr *addr, char *name, int *auth_dns);
|
||||||
int fix_fd(int fd);
|
int fix_fd(int fd);
|
||||||
struct in_addr get_ifaddr(char *intr);
|
struct in_addr get_ifaddr(char *intr);
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
@@ -876,47 +1006,46 @@ int set_ipv6pktinfo(int fd);
|
|||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
void dhcp_init(void);
|
void dhcp_init(void);
|
||||||
void dhcp_packet(time_t now, int pxe_fd);
|
void dhcp_packet(time_t now, int pxe_fd);
|
||||||
ssize_t recv_dhcp_packet(int fd, struct msghdr *msg);
|
|
||||||
struct dhcp_context *address_available(struct dhcp_context *context,
|
struct dhcp_context *address_available(struct dhcp_context *context,
|
||||||
struct in_addr addr,
|
struct in_addr addr,
|
||||||
struct dhcp_netid *netids);
|
struct dhcp_netid *netids);
|
||||||
struct dhcp_context *narrow_context(struct dhcp_context *context,
|
struct dhcp_context *narrow_context(struct dhcp_context *context,
|
||||||
struct in_addr taddr,
|
struct in_addr taddr,
|
||||||
struct dhcp_netid *netids);
|
struct dhcp_netid *netids);
|
||||||
int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
|
|
||||||
int address_allocate(struct dhcp_context *context,
|
int address_allocate(struct dhcp_context *context,
|
||||||
struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
|
struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
|
||||||
struct dhcp_netid *netids, time_t now);
|
struct dhcp_netid *netids, time_t now);
|
||||||
struct dhcp_netid *run_tag_if(struct dhcp_netid *input);
|
|
||||||
int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
|
int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
|
||||||
struct dhcp_config *find_config(struct dhcp_config *configs,
|
struct dhcp_config *find_config(struct dhcp_config *configs,
|
||||||
struct dhcp_context *context,
|
struct dhcp_context *context,
|
||||||
unsigned char *clid, int clid_len,
|
unsigned char *clid, int clid_len,
|
||||||
unsigned char *hwaddr, int hw_len,
|
unsigned char *hwaddr, int hw_len,
|
||||||
int hw_type, char *hostname);
|
int hw_type, char *hostname);
|
||||||
void dhcp_update_configs(struct dhcp_config *configs);
|
|
||||||
void dhcp_read_ethers(void);
|
void dhcp_read_ethers(void);
|
||||||
void check_dhcp_hosts(int fatal);
|
|
||||||
struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr);
|
struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr);
|
||||||
char *strip_hostname(char *hostname);
|
|
||||||
char *host_from_dns(struct in_addr addr);
|
char *host_from_dns(struct in_addr addr);
|
||||||
char *get_domain(struct in_addr addr);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lease.c */
|
/* lease.c */
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
void lease_update_file(time_t now);
|
void lease_update_file(time_t now);
|
||||||
void lease_update_dns();
|
void lease_update_dns(int force);
|
||||||
void lease_init(time_t now);
|
void lease_init(time_t now);
|
||||||
struct dhcp_lease *lease_allocate4(struct in_addr addr);
|
struct dhcp_lease *lease4_allocate(struct in_addr addr);
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
struct dhcp_lease *lease_allocate6(struct in6_addr *addrp);
|
struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type);
|
||||||
|
struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len,
|
||||||
|
int lease_type, int iaid, struct in6_addr *addr);
|
||||||
|
void lease6_filter(int lease_type, int iaid, struct dhcp_context *context);
|
||||||
|
struct dhcp_lease *lease6_find_by_addr(struct in6_addr *net, int prefix, u64 addr);
|
||||||
|
u64 lease_find_max_addr6(struct dhcp_context *context);
|
||||||
|
void lease_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface);
|
||||||
#endif
|
#endif
|
||||||
void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
|
void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
|
||||||
unsigned char *clid, int hw_len, int hw_type, int clid_len);
|
unsigned char *clid, int hw_len, int hw_type, int clid_len, time_t now, int force);
|
||||||
void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth);
|
void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth, char *domain, char *config_domain);
|
||||||
void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now);
|
void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now);
|
||||||
void lease_set_interface(struct dhcp_lease *lease, int interface);
|
void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now);
|
||||||
struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type,
|
struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type,
|
||||||
unsigned char *clid, int clid_len);
|
unsigned char *clid, int clid_len);
|
||||||
struct dhcp_lease *lease_find_by_addr(struct in_addr addr);
|
struct dhcp_lease *lease_find_by_addr(struct in_addr addr);
|
||||||
@@ -925,6 +1054,11 @@ void lease_prune(struct dhcp_lease *target, time_t now);
|
|||||||
void lease_update_from_configs(void);
|
void lease_update_from_configs(void);
|
||||||
int do_script_run(time_t now);
|
int do_script_run(time_t now);
|
||||||
void rerun_scripts(void);
|
void rerun_scripts(void);
|
||||||
|
void lease_find_interfaces(time_t now);
|
||||||
|
#ifdef HAVE_SCRIPT
|
||||||
|
void lease_add_extradata(struct dhcp_lease *lease, unsigned char *data,
|
||||||
|
unsigned int len, int delim);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* rfc2131.c */
|
/* rfc2131.c */
|
||||||
@@ -940,6 +1074,7 @@ unsigned char *extended_hwaddr(int hwtype, int hwlen, unsigned char *hwaddr,
|
|||||||
int make_icmp_sock(void);
|
int make_icmp_sock(void);
|
||||||
int icmp_ping(struct in_addr addr);
|
int icmp_ping(struct in_addr addr);
|
||||||
#endif
|
#endif
|
||||||
|
void send_alarm(time_t event, time_t now);
|
||||||
void send_event(int fd, int event, int data, char *msg);
|
void send_event(int fd, int event, int data, char *msg);
|
||||||
void clear_cache_and_reload(time_t now);
|
void clear_cache_and_reload(time_t now);
|
||||||
void poll_resolv(int force, int do_reload, time_t now);
|
void poll_resolv(int force, int do_reload, time_t now);
|
||||||
@@ -947,7 +1082,7 @@ void poll_resolv(int force, int do_reload, time_t now);
|
|||||||
/* netlink.c */
|
/* netlink.c */
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
void netlink_init(void);
|
void netlink_init(void);
|
||||||
void netlink_multicast(void);
|
void netlink_multicast(time_t now);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* bpf.c */
|
/* bpf.c */
|
||||||
@@ -971,11 +1106,14 @@ void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* helper.c */
|
/* helper.c */
|
||||||
#if defined(HAVE_DHCP) && !defined(NO_FORK)
|
#if defined(HAVE_SCRIPT)
|
||||||
int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd);
|
int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd);
|
||||||
void helper_write(void);
|
void helper_write(void);
|
||||||
void queue_script(int action, struct dhcp_lease *lease,
|
void queue_script(int action, struct dhcp_lease *lease,
|
||||||
char *hostname, time_t now);
|
char *hostname, time_t now);
|
||||||
|
#ifdef HAVE_TFTP
|
||||||
|
void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer);
|
||||||
|
#endif
|
||||||
int helper_buf_empty(void);
|
int helper_buf_empty(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -983,6 +1121,7 @@ int helper_buf_empty(void);
|
|||||||
#ifdef HAVE_TFTP
|
#ifdef HAVE_TFTP
|
||||||
void tftp_request(struct listener *listen, time_t now);
|
void tftp_request(struct listener *listen, time_t now);
|
||||||
void check_tftp_listeners(fd_set *rset, time_t now);
|
void check_tftp_listeners(fd_set *rset, time_t now);
|
||||||
|
int do_tftp_script_run(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* conntrack.c */
|
/* conntrack.c */
|
||||||
@@ -991,8 +1130,86 @@ int get_incoming_mark(union mysockaddr *peer_addr, struct all_addr *local_addr,
|
|||||||
int istcp, unsigned int *markp);
|
int istcp, unsigned int *markp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* dhcp6.c */
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
void dhcp6_init(void);
|
||||||
|
void dhcp6_packet(time_t now);
|
||||||
|
int address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len,
|
||||||
|
int serial, struct dhcp_netid *netids, struct in6_addr *ans);
|
||||||
|
int is_addr_in_context6(struct dhcp_context *context, struct in6_addr *addr);
|
||||||
|
struct dhcp_context *address6_available(struct dhcp_context *context,
|
||||||
|
struct in6_addr *taddr,
|
||||||
|
struct dhcp_netid *netids);
|
||||||
|
struct dhcp_context *narrow_context6(struct dhcp_context *context,
|
||||||
|
struct in6_addr *taddr,
|
||||||
|
struct dhcp_netid *netids);
|
||||||
|
struct dhcp_config *find_config6(struct dhcp_config *configs,
|
||||||
|
struct dhcp_context *context,
|
||||||
|
unsigned char *duid, int duid_len,
|
||||||
|
char *hostname);
|
||||||
|
struct dhcp_config *config_find_by_address6(struct dhcp_config *configs, struct in6_addr *net,
|
||||||
|
int prefix, u64 addr);
|
||||||
|
void make_duid(time_t now);
|
||||||
|
void dhcp_construct_contexts(time_t now);
|
||||||
|
void join_multicast(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* rfc3315.c */
|
/* rfc3315.c */
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
void make_duid(time_t now);
|
unsigned short dhcp6_reply(struct dhcp_context *context, int interface, char *iface_name,
|
||||||
size_t dhcp6_reply(struct dhcp_context *context, size_t sz);
|
struct in6_addr *fallback, size_t sz, int is_multicast, time_t now);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* dhcp-common.c */
|
||||||
|
#ifdef HAVE_DHCP
|
||||||
|
void dhcp_common_init(void);
|
||||||
|
ssize_t recv_dhcp_packet(int fd, struct msghdr *msg);
|
||||||
|
struct dhcp_netid *run_tag_if(struct dhcp_netid *input);
|
||||||
|
struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *context_tags,
|
||||||
|
struct dhcp_opt *opts);
|
||||||
|
int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
|
||||||
|
char *strip_hostname(char *hostname);
|
||||||
|
void log_tags(struct dhcp_netid *netid, u32 xid);
|
||||||
|
int match_bytes(struct dhcp_opt *o, unsigned char *p, int len);
|
||||||
|
void dhcp_update_configs(struct dhcp_config *configs);
|
||||||
|
void display_opts(void);
|
||||||
|
u16 lookup_dhcp_opt(int prot, char *name);
|
||||||
|
u16 lookup_dhcp_len(int prot, u16 val);
|
||||||
|
char *option_string(int prot, unsigned int opt, unsigned char *val,
|
||||||
|
int opt_len, char *buf, int buf_len);
|
||||||
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
|
void bindtodevice(int fd);
|
||||||
|
#endif
|
||||||
|
# ifdef HAVE_DHCP6
|
||||||
|
void display_opts6(void);
|
||||||
|
# endif
|
||||||
|
void log_context(int family, struct dhcp_context *context);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* outpacket.c */
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
void end_opt6(int container);
|
||||||
|
int save_counter(int newval);
|
||||||
|
void *expand(size_t headroom);
|
||||||
|
int new_opt6(int opt);
|
||||||
|
void *put_opt6(void *data, size_t len);
|
||||||
|
void put_opt6_long(unsigned int val);
|
||||||
|
void put_opt6_short(unsigned int val);
|
||||||
|
void put_opt6_char(unsigned int val);
|
||||||
|
void put_opt6_string(char *s);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* radv.c */
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
void ra_init(time_t now);
|
||||||
|
void icmp6_packet(time_t now);
|
||||||
|
time_t periodic_ra(time_t now);
|
||||||
|
void ra_start_unsolicted(time_t now, struct dhcp_context *context);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* slaac.c */
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
void slaac_add_addrs(struct dhcp_lease *lease, time_t now, int force);
|
||||||
|
time_t periodic_slaac(time_t now, struct dhcp_lease *leases);
|
||||||
|
void slaac_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface, struct dhcp_lease *leases);
|
||||||
#endif
|
#endif
|
||||||
+209
-162
@@ -26,9 +26,9 @@ static struct randfd *allocate_rfd(int family);
|
|||||||
|
|
||||||
/* Send a UDP packet with its source address set as "source"
|
/* Send a UDP packet with its source address set as "source"
|
||||||
unless nowild is true, when we just send it with the kernel default */
|
unless nowild is true, when we just send it with the kernel default */
|
||||||
void send_from(int fd, int nowild, char *packet, size_t len,
|
int send_from(int fd, int nowild, char *packet, size_t len,
|
||||||
union mysockaddr *to, struct all_addr *source,
|
union mysockaddr *to, struct all_addr *source,
|
||||||
unsigned int iface)
|
unsigned int iface)
|
||||||
{
|
{
|
||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
struct iovec iov[1];
|
struct iovec iov[1];
|
||||||
@@ -95,20 +95,20 @@ void send_from(int fd, int nowild, char *packet, size_t len,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
retry:
|
while (sendmsg(fd, &msg, 0) == -1)
|
||||||
if (sendmsg(fd, &msg, 0) == -1)
|
|
||||||
{
|
{
|
||||||
/* certain Linux kernels seem to object to setting the source address in the IPv6 stack
|
|
||||||
by returning EINVAL from sendmsg. In that case, try again without setting the
|
|
||||||
source address, since it will nearly alway be correct anyway. IPv6 stinks. */
|
|
||||||
if (errno == EINVAL && msg.msg_controllen)
|
|
||||||
{
|
|
||||||
msg.msg_controllen = 0;
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
if (retry_send())
|
if (retry_send())
|
||||||
goto retry;
|
continue;
|
||||||
|
|
||||||
|
/* If interface is still in DAD, EINVAL results - ignore that. */
|
||||||
|
if (errno == EINVAL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
my_syslog(LOG_ERR, _("failed to send packet: %s"), strerror(errno));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int search_servers(time_t now, struct all_addr **addrpp,
|
static unsigned int search_servers(time_t now, struct all_addr **addrpp,
|
||||||
@@ -429,7 +429,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
|
|||||||
if (udpfd != -1)
|
if (udpfd != -1)
|
||||||
{
|
{
|
||||||
plen = setup_reply(header, plen, addrp, flags, daemon->local_ttl);
|
plen = setup_reply(header, plen, addrp, flags, daemon->local_ttl);
|
||||||
send_from(udpfd, option_bool(OPT_NOWILD), (char *)header, plen, udpaddr, dst_addr, dst_iface);
|
send_from(udpfd, option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND), (char *)header, plen, udpaddr, dst_addr, dst_iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -617,7 +617,7 @@ void reply_query(int fd, int family, time_t now)
|
|||||||
{
|
{
|
||||||
header->id = htons(forward->orig_id);
|
header->id = htons(forward->orig_id);
|
||||||
header->hb4 |= HB4_RA; /* recursion if available */
|
header->hb4 |= HB4_RA; /* recursion if available */
|
||||||
send_from(forward->fd, option_bool(OPT_NOWILD), daemon->packet, nn,
|
send_from(forward->fd, option_bool(OPT_NOWILD) || option_bool (OPT_CLEVERBIND), daemon->packet, nn,
|
||||||
&forward->source, &forward->dest, forward->iface);
|
&forward->source, &forward->dest, forward->iface);
|
||||||
}
|
}
|
||||||
free_frec(forward); /* cancel */
|
free_frec(forward); /* cancel */
|
||||||
@@ -635,6 +635,7 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
size_t m;
|
size_t m;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
int if_index = 0;
|
int if_index = 0;
|
||||||
|
int auth_dns = 0;
|
||||||
struct iovec iov[1];
|
struct iovec iov[1];
|
||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
struct cmsghdr *cmptr;
|
struct cmsghdr *cmptr;
|
||||||
@@ -657,17 +658,20 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
/* packet buffer overwritten */
|
/* packet buffer overwritten */
|
||||||
daemon->srv_save = NULL;
|
daemon->srv_save = NULL;
|
||||||
|
|
||||||
if (listen->family == AF_INET && option_bool(OPT_NOWILD))
|
dst_addr_4.s_addr = 0;
|
||||||
|
netmask.s_addr = 0;
|
||||||
|
|
||||||
|
if (listen->iface && option_bool(OPT_NOWILD))
|
||||||
{
|
{
|
||||||
dst_addr_4 = listen->iface->addr.in.sin_addr;
|
auth_dns = listen->iface->dns_auth;
|
||||||
netmask = listen->iface->netmask;
|
|
||||||
|
if (listen->family == AF_INET)
|
||||||
|
{
|
||||||
|
dst_addr_4 = listen->iface->addr.in.sin_addr;
|
||||||
|
netmask = listen->iface->netmask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
dst_addr_4.s_addr = 0;
|
|
||||||
netmask.s_addr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
iov[0].iov_base = daemon->packet;
|
iov[0].iov_base = daemon->packet;
|
||||||
iov[0].iov_len = daemon->edns_pktsz;
|
iov[0].iov_len = daemon->edns_pktsz;
|
||||||
|
|
||||||
@@ -760,22 +764,43 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
/* enforce available interface configuration */
|
/* enforce available interface configuration */
|
||||||
|
|
||||||
if (!indextoname(listen->fd, if_index, ifr.ifr_name) ||
|
if (!indextoname(listen->fd, if_index, ifr.ifr_name) ||
|
||||||
!iface_check(listen->family, &dst_addr, ifr.ifr_name))
|
!iface_check(listen->family, &dst_addr, ifr.ifr_name, &auth_dns))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (listen->family == AF_INET &&
|
if (listen->family == AF_INET && option_bool(OPT_LOCALISE))
|
||||||
option_bool(OPT_LOCALISE) &&
|
{
|
||||||
ioctl(listen->fd, SIOCGIFNETMASK, &ifr) == -1)
|
struct irec *iface;
|
||||||
return;
|
|
||||||
|
/* get the netmask of the interface whch has the address we were sent to.
|
||||||
netmask = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr;
|
This is no neccessarily the interface we arrived on. */
|
||||||
|
|
||||||
|
for (iface = daemon->interfaces; iface; iface = iface->next)
|
||||||
|
if (iface->addr.sa.sa_family == AF_INET &&
|
||||||
|
iface->addr.in.sin_addr.s_addr == dst_addr_4.s_addr)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* interface may be new */
|
||||||
|
if (!iface)
|
||||||
|
enumerate_interfaces();
|
||||||
|
|
||||||
|
for (iface = daemon->interfaces; iface; iface = iface->next)
|
||||||
|
if (iface->addr.sa.sa_family == AF_INET &&
|
||||||
|
iface->addr.in.sin_addr.s_addr == dst_addr_4.s_addr)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* If we failed, abandon localisation */
|
||||||
|
if (iface)
|
||||||
|
netmask = iface->netmask;
|
||||||
|
else
|
||||||
|
dst_addr_4.s_addr = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extract_request(header, (size_t)n, daemon->namebuff, &type))
|
if (extract_request(header, (size_t)n, daemon->namebuff, &type))
|
||||||
{
|
{
|
||||||
char types[20];
|
char types[20];
|
||||||
|
|
||||||
querystr(types, type);
|
querystr(auth_dns ? "auth" : "query", types, type);
|
||||||
|
|
||||||
if (listen->family == AF_INET)
|
if (listen->family == AF_INET)
|
||||||
log_query(F_QUERY | F_IPV4 | F_FORWARD, daemon->namebuff,
|
log_query(F_QUERY | F_IPV4 | F_FORWARD, daemon->namebuff,
|
||||||
@@ -787,19 +812,32 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
m = answer_request (header, ((char *) header) + PACKETSZ, (size_t)n,
|
#ifdef HAVE_AUTH
|
||||||
dst_addr_4, netmask, now);
|
if (auth_dns)
|
||||||
if (m >= 1)
|
|
||||||
{
|
{
|
||||||
send_from(listen->fd, option_bool(OPT_NOWILD), (char *)header,
|
m = answer_auth(header, ((char *) header) + PACKETSZ, (size_t)n, now, &source_addr);
|
||||||
m, &source_addr, &dst_addr, if_index);
|
if (m >= 1)
|
||||||
daemon->local_answer++;
|
send_from(listen->fd, option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND),
|
||||||
|
(char *)header, m, &source_addr, &dst_addr, if_index);
|
||||||
}
|
}
|
||||||
else if (forward_query(listen->fd, &source_addr, &dst_addr, if_index,
|
|
||||||
header, (size_t)n, now, NULL))
|
|
||||||
daemon->queries_forwarded++;
|
|
||||||
else
|
else
|
||||||
daemon->local_answer++;
|
#endif
|
||||||
|
{
|
||||||
|
m = answer_request(header, ((char *) header) + PACKETSZ, (size_t)n,
|
||||||
|
dst_addr_4, netmask, now);
|
||||||
|
|
||||||
|
if (m >= 1)
|
||||||
|
{
|
||||||
|
send_from(listen->fd, option_bool(OPT_NOWILD) || option_bool(OPT_CLEVERBIND),
|
||||||
|
(char *)header, m, &source_addr, &dst_addr, if_index);
|
||||||
|
daemon->local_answer++;
|
||||||
|
}
|
||||||
|
else if (forward_query(listen->fd, &source_addr, &dst_addr, if_index,
|
||||||
|
header, (size_t)n, now, NULL))
|
||||||
|
daemon->queries_forwarded++;
|
||||||
|
else
|
||||||
|
daemon->local_answer++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The daemon forks before calling this: it should deal with one connection,
|
/* The daemon forks before calling this: it should deal with one connection,
|
||||||
@@ -807,13 +845,14 @@ void receive_query(struct listener *listen, time_t now)
|
|||||||
about resources for debug mode, when the fork is suppressed: that's
|
about resources for debug mode, when the fork is suppressed: that's
|
||||||
done by the caller. */
|
done by the caller. */
|
||||||
unsigned char *tcp_request(int confd, time_t now,
|
unsigned char *tcp_request(int confd, time_t now,
|
||||||
union mysockaddr *local_addr, struct in_addr netmask)
|
union mysockaddr *local_addr, struct in_addr netmask, int auth_dns)
|
||||||
{
|
{
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int norebind = 0;
|
int norebind = 0;
|
||||||
int checking_disabled;
|
int checking_disabled;
|
||||||
size_t m;
|
size_t m;
|
||||||
unsigned short qtype, gotname;
|
unsigned short qtype;
|
||||||
|
unsigned int gotname;
|
||||||
unsigned char c1, c2;
|
unsigned char c1, c2;
|
||||||
/* Max TCP packet + slop */
|
/* Max TCP packet + slop */
|
||||||
unsigned char *packet = whine_malloc(65536 + MAXDNAME + RRFIXEDSZ);
|
unsigned char *packet = whine_malloc(65536 + MAXDNAME + RRFIXEDSZ);
|
||||||
@@ -849,7 +888,7 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
{
|
{
|
||||||
char types[20];
|
char types[20];
|
||||||
|
|
||||||
querystr(types, qtype);
|
querystr(auth_dns ? "auth" : "query", types, qtype);
|
||||||
|
|
||||||
if (peer_addr.sa.sa_family == AF_INET)
|
if (peer_addr.sa.sa_family == AF_INET)
|
||||||
log_query(F_QUERY | F_IPV4 | F_FORWARD, daemon->namebuff,
|
log_query(F_QUERY | F_IPV4 | F_FORWARD, daemon->namebuff,
|
||||||
@@ -866,142 +905,150 @@ unsigned char *tcp_request(int confd, time_t now,
|
|||||||
else
|
else
|
||||||
dst_addr_4.s_addr = 0;
|
dst_addr_4.s_addr = 0;
|
||||||
|
|
||||||
/* m > 0 if answered from cache */
|
#ifdef HAVE_AUTH
|
||||||
m = answer_request(header, ((char *) header) + 65536, (unsigned int)size,
|
if (auth_dns)
|
||||||
dst_addr_4, netmask, now);
|
m = answer_auth(header, ((char *) header) + 65536, (size_t)size, now, &peer_addr);
|
||||||
|
else
|
||||||
/* Do this by steam now we're not in the select() loop */
|
#endif
|
||||||
check_log_writer(NULL);
|
|
||||||
|
|
||||||
if (m == 0)
|
|
||||||
{
|
{
|
||||||
unsigned int flags = 0;
|
/* m > 0 if answered from cache */
|
||||||
struct all_addr *addrp = NULL;
|
m = answer_request(header, ((char *) header) + 65536, (size_t)size,
|
||||||
int type = 0;
|
dst_addr_4, netmask, now);
|
||||||
char *domain = NULL;
|
|
||||||
|
|
||||||
if (option_bool(OPT_ADD_MAC))
|
|
||||||
size = add_mac(header, size, ((char *) header) + 65536, &peer_addr);
|
|
||||||
|
|
||||||
if (gotname)
|
|
||||||
flags = search_servers(now, &addrp, gotname, daemon->namebuff, &type, &domain, &norebind);
|
|
||||||
|
|
||||||
if (type != 0 || option_bool(OPT_ORDER) || !daemon->last_server)
|
/* Do this by steam now we're not in the select() loop */
|
||||||
last_server = daemon->servers;
|
check_log_writer(NULL);
|
||||||
else
|
|
||||||
last_server = daemon->last_server;
|
if (m == 0)
|
||||||
|
|
||||||
if (!flags && last_server)
|
|
||||||
{
|
{
|
||||||
struct server *firstsendto = NULL;
|
unsigned int flags = 0;
|
||||||
unsigned int crc = questions_crc(header, (unsigned int)size, daemon->namebuff);
|
struct all_addr *addrp = NULL;
|
||||||
|
int type = 0;
|
||||||
/* Loop round available servers until we succeed in connecting to one.
|
char *domain = NULL;
|
||||||
Note that this code subtley ensures that consecutive queries on this connection
|
|
||||||
which can go to the same server, do so. */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
if (!firstsendto)
|
|
||||||
firstsendto = last_server;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(last_server = last_server->next))
|
|
||||||
last_server = daemon->servers;
|
|
||||||
|
|
||||||
if (last_server == firstsendto)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* server for wrong domain */
|
if (option_bool(OPT_ADD_MAC))
|
||||||
if (type != (last_server->flags & SERV_TYPE) ||
|
size = add_mac(header, size, ((char *) header) + 65536, &peer_addr);
|
||||||
(type == SERV_HAS_DOMAIN && !hostname_isequal(domain, last_server->domain)))
|
|
||||||
continue;
|
if (gotname)
|
||||||
|
flags = search_servers(now, &addrp, gotname, daemon->namebuff, &type, &domain, &norebind);
|
||||||
if (last_server->tcpfd == -1)
|
|
||||||
|
if (type != 0 || option_bool(OPT_ORDER) || !daemon->last_server)
|
||||||
|
last_server = daemon->servers;
|
||||||
|
else
|
||||||
|
last_server = daemon->last_server;
|
||||||
|
|
||||||
|
if (!flags && last_server)
|
||||||
|
{
|
||||||
|
struct server *firstsendto = NULL;
|
||||||
|
unsigned int crc = questions_crc(header, (unsigned int)size, daemon->namebuff);
|
||||||
|
|
||||||
|
/* Loop round available servers until we succeed in connecting to one.
|
||||||
|
Note that this code subtley ensures that consecutive queries on this connection
|
||||||
|
which can go to the same server, do so. */
|
||||||
|
while (1)
|
||||||
{
|
{
|
||||||
if ((last_server->tcpfd = socket(last_server->addr.sa.sa_family, SOCK_STREAM, 0)) == -1)
|
if (!firstsendto)
|
||||||
|
firstsendto = last_server;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(last_server = last_server->next))
|
||||||
|
last_server = daemon->servers;
|
||||||
|
|
||||||
|
if (last_server == firstsendto)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* server for wrong domain */
|
||||||
|
if (type != (last_server->flags & SERV_TYPE) ||
|
||||||
|
(type == SERV_HAS_DOMAIN && !hostname_isequal(domain, last_server->domain)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((!local_bind(last_server->tcpfd, &last_server->source_addr, last_server->interface, 1) ||
|
if (last_server->tcpfd == -1)
|
||||||
connect(last_server->tcpfd, &last_server->addr.sa, sa_len(&last_server->addr)) == -1))
|
{
|
||||||
|
if ((last_server->tcpfd = socket(last_server->addr.sa.sa_family, SOCK_STREAM, 0)) == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((!local_bind(last_server->tcpfd, &last_server->source_addr, last_server->interface, 1) ||
|
||||||
|
connect(last_server->tcpfd, &last_server->addr.sa, sa_len(&last_server->addr)) == -1))
|
||||||
|
{
|
||||||
|
close(last_server->tcpfd);
|
||||||
|
last_server->tcpfd = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_CONNTRACK
|
||||||
|
/* Copy connection mark of incoming query to outgoing connection. */
|
||||||
|
if (option_bool(OPT_CONNTRACK))
|
||||||
|
{
|
||||||
|
unsigned int mark;
|
||||||
|
struct all_addr local;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (local_addr->sa.sa_family == AF_INET6)
|
||||||
|
local.addr.addr6 = local_addr->in6.sin6_addr;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
local.addr.addr4 = local_addr->in.sin_addr;
|
||||||
|
|
||||||
|
if (get_incoming_mark(&peer_addr, &local, 1, &mark))
|
||||||
|
setsockopt(last_server->tcpfd, SOL_SOCKET, SO_MARK, &mark, sizeof(unsigned int));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
c1 = size >> 8;
|
||||||
|
c2 = size;
|
||||||
|
|
||||||
|
if (!read_write(last_server->tcpfd, &c1, 1, 0) ||
|
||||||
|
!read_write(last_server->tcpfd, &c2, 1, 0) ||
|
||||||
|
!read_write(last_server->tcpfd, packet, size, 0) ||
|
||||||
|
!read_write(last_server->tcpfd, &c1, 1, 1) ||
|
||||||
|
!read_write(last_server->tcpfd, &c2, 1, 1))
|
||||||
{
|
{
|
||||||
close(last_server->tcpfd);
|
close(last_server->tcpfd);
|
||||||
last_server->tcpfd = -1;
|
last_server->tcpfd = -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CONNTRACK
|
m = (c1 << 8) | c2;
|
||||||
/* Copy connection mark of incoming query to outgoing connection. */
|
if (!read_write(last_server->tcpfd, packet, m, 1))
|
||||||
if (option_bool(OPT_CONNTRACK))
|
return packet;
|
||||||
{
|
|
||||||
unsigned int mark;
|
if (!gotname)
|
||||||
struct all_addr local;
|
strcpy(daemon->namebuff, "query");
|
||||||
#ifdef HAVE_IPV6
|
if (last_server->addr.sa.sa_family == AF_INET)
|
||||||
if (local_addr->sa.sa_family == AF_INET6)
|
log_query(F_SERVER | F_IPV4 | F_FORWARD, daemon->namebuff,
|
||||||
local.addr.addr6 = local_addr->in6.sin6_addr;
|
(struct all_addr *)&last_server->addr.in.sin_addr, NULL);
|
||||||
else
|
|
||||||
#endif
|
|
||||||
local.addr.addr4 = local_addr->in.sin_addr;
|
|
||||||
|
|
||||||
if (get_incoming_mark(&peer_addr, &local, 1, &mark))
|
|
||||||
setsockopt(last_server->tcpfd, SOL_SOCKET, SO_MARK, &mark, sizeof(unsigned int));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
c1 = size >> 8;
|
|
||||||
c2 = size;
|
|
||||||
|
|
||||||
if (!read_write(last_server->tcpfd, &c1, 1, 0) ||
|
|
||||||
!read_write(last_server->tcpfd, &c2, 1, 0) ||
|
|
||||||
!read_write(last_server->tcpfd, packet, size, 0) ||
|
|
||||||
!read_write(last_server->tcpfd, &c1, 1, 1) ||
|
|
||||||
!read_write(last_server->tcpfd, &c2, 1, 1))
|
|
||||||
{
|
|
||||||
close(last_server->tcpfd);
|
|
||||||
last_server->tcpfd = -1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
m = (c1 << 8) | c2;
|
|
||||||
if (!read_write(last_server->tcpfd, packet, m, 1))
|
|
||||||
return packet;
|
|
||||||
|
|
||||||
if (!gotname)
|
|
||||||
strcpy(daemon->namebuff, "query");
|
|
||||||
if (last_server->addr.sa.sa_family == AF_INET)
|
|
||||||
log_query(F_SERVER | F_IPV4 | F_FORWARD, daemon->namebuff,
|
|
||||||
(struct all_addr *)&last_server->addr.in.sin_addr, NULL);
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
else
|
else
|
||||||
log_query(F_SERVER | F_IPV6 | F_FORWARD, daemon->namebuff,
|
log_query(F_SERVER | F_IPV6 | F_FORWARD, daemon->namebuff,
|
||||||
(struct all_addr *)&last_server->addr.in6.sin6_addr, NULL);
|
(struct all_addr *)&last_server->addr.in6.sin6_addr, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* There's no point in updating the cache, since this process will exit and
|
/* There's no point in updating the cache, since this process will exit and
|
||||||
lose the information after a few queries. We make this call for the alias and
|
lose the information after a few queries. We make this call for the alias and
|
||||||
bogus-nxdomain side-effects. */
|
bogus-nxdomain side-effects. */
|
||||||
/* If the crc of the question section doesn't match the crc we sent, then
|
/* If the crc of the question section doesn't match the crc we sent, then
|
||||||
someone might be attempting to insert bogus values into the cache by
|
someone might be attempting to insert bogus values into the cache by
|
||||||
sending replies containing questions and bogus answers. */
|
sending replies containing questions and bogus answers. */
|
||||||
if (crc == questions_crc(header, (unsigned int)m, daemon->namebuff))
|
if (crc == questions_crc(header, (unsigned int)m, daemon->namebuff))
|
||||||
m = process_reply(header, now, last_server, (unsigned int)m,
|
m = process_reply(header, now, last_server, (unsigned int)m,
|
||||||
option_bool(OPT_NO_REBIND) && !norebind, checking_disabled);
|
option_bool(OPT_NO_REBIND) && !norebind, checking_disabled);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* In case of local answer or no connections made. */
|
||||||
|
if (m == 0)
|
||||||
|
m = setup_reply(header, (unsigned int)size, addrp, flags, daemon->local_ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In case of local answer or no connections made. */
|
|
||||||
if (m == 0)
|
|
||||||
m = setup_reply(header, (unsigned int)size, addrp, flags, daemon->local_ttl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_log_writer(NULL);
|
check_log_writer(NULL);
|
||||||
|
|
||||||
c1 = m>>8;
|
c1 = m>>8;
|
||||||
c2 = m;
|
c2 = m;
|
||||||
if (!read_write(confd, &c1, 1, 0) ||
|
if (m == 0 ||
|
||||||
|
!read_write(confd, &c1, 1, 0) ||
|
||||||
!read_write(confd, &c2, 1, 0) ||
|
!read_write(confd, &c2, 1, 0) ||
|
||||||
!read_write(confd, packet, m, 0))
|
!read_write(confd, packet, m, 0))
|
||||||
return packet;
|
return packet;
|
||||||
|
|||||||
+338
-156
@@ -34,10 +34,15 @@ static void my_setenv(const char *name, const char *value, int *error);
|
|||||||
static unsigned char *grab_extradata(unsigned char *buf, unsigned char *end, char *env, int *err);
|
static unsigned char *grab_extradata(unsigned char *buf, unsigned char *end, char *env, int *err);
|
||||||
|
|
||||||
#ifdef HAVE_LUASCRIPT
|
#ifdef HAVE_LUASCRIPT
|
||||||
|
#define LUA_COMPAT_ALL
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
#ifndef lua_open
|
||||||
|
#define lua_open() luaL_newstate()
|
||||||
|
#endif
|
||||||
|
|
||||||
lua_State *lua;
|
lua_State *lua;
|
||||||
|
|
||||||
static unsigned char *grab_extradata_lua(unsigned char *buf, unsigned char *end, char *field);
|
static unsigned char *grab_extradata_lua(unsigned char *buf, unsigned char *end, char *field);
|
||||||
@@ -46,8 +51,9 @@ static unsigned char *grab_extradata_lua(unsigned char *buf, unsigned char *end,
|
|||||||
|
|
||||||
struct script_data
|
struct script_data
|
||||||
{
|
{
|
||||||
unsigned char action, hwaddr_len, hwaddr_type;
|
int flags;
|
||||||
unsigned char clid_len, hostname_len, ed_len;
|
int action, hwaddr_len, hwaddr_type;
|
||||||
|
int clid_len, hostname_len, ed_len;
|
||||||
struct in_addr addr, giaddr;
|
struct in_addr addr, giaddr;
|
||||||
unsigned int remaining_time;
|
unsigned int remaining_time;
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
@@ -57,6 +63,7 @@ struct script_data
|
|||||||
#endif
|
#endif
|
||||||
unsigned char hwaddr[DHCP_CHADDR_MAX];
|
unsigned char hwaddr[DHCP_CHADDR_MAX];
|
||||||
char interface[IF_NAMESIZE];
|
char interface[IF_NAMESIZE];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct script_data *buf = NULL;
|
static struct script_data *buf = NULL;
|
||||||
@@ -173,7 +180,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
char *p, *action_str, *hostname = NULL, *domain = NULL;
|
char *p, *action_str, *hostname = NULL, *domain = NULL;
|
||||||
unsigned char *buf = (unsigned char *)daemon->namebuff;
|
unsigned char *buf = (unsigned char *)daemon->namebuff;
|
||||||
unsigned char *end, *extradata, *alloc_buff = NULL;
|
unsigned char *end, *extradata, *alloc_buff = NULL;
|
||||||
int err = 0;
|
int is6, err = 0;
|
||||||
|
|
||||||
free(alloc_buff);
|
free(alloc_buff);
|
||||||
|
|
||||||
@@ -190,26 +197,37 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
#endif
|
#endif
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is6 = !!(data.flags & (LEASE_TA | LEASE_NA));
|
||||||
|
|
||||||
if (data.action == ACTION_DEL)
|
if (data.action == ACTION_DEL)
|
||||||
action_str = "del";
|
action_str = "del";
|
||||||
else if (data.action == ACTION_ADD)
|
else if (data.action == ACTION_ADD)
|
||||||
action_str = "add";
|
action_str = "add";
|
||||||
else if (data.action == ACTION_OLD || data.action == ACTION_OLD_HOSTNAME)
|
else if (data.action == ACTION_OLD || data.action == ACTION_OLD_HOSTNAME)
|
||||||
action_str = "old";
|
action_str = "old";
|
||||||
|
else if (data.action == ACTION_TFTP)
|
||||||
|
{
|
||||||
|
action_str = "tftp";
|
||||||
|
is6 = (data.flags != AF_INET);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* stringify MAC into dhcp_buff */
|
|
||||||
p = daemon->dhcp_buff;
|
if (!is6)
|
||||||
if (data.hwaddr_type != ARPHRD_ETHER || data.hwaddr_len == 0)
|
{
|
||||||
p += sprintf(p, "%.2x-", data.hwaddr_type);
|
/* stringify MAC into dhcp_buff */
|
||||||
for (i = 0; (i < data.hwaddr_len) && (i < DHCP_CHADDR_MAX); i++)
|
p = daemon->dhcp_buff;
|
||||||
{
|
if (data.hwaddr_type != ARPHRD_ETHER || data.hwaddr_len == 0)
|
||||||
p += sprintf(p, "%.2x", data.hwaddr[i]);
|
p += sprintf(p, "%.2x-", data.hwaddr_type);
|
||||||
if (i != data.hwaddr_len - 1)
|
for (i = 0; (i < data.hwaddr_len) && (i < DHCP_CHADDR_MAX); i++)
|
||||||
p += sprintf(p, ":");
|
{
|
||||||
}
|
p += sprintf(p, "%.2x", data.hwaddr[i]);
|
||||||
|
if (i != data.hwaddr_len - 1)
|
||||||
|
p += sprintf(p, ":");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* expiry or length into dhcp_buff2 */
|
/* expiry or length into dhcp_buff2 */
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
@@ -228,12 +246,34 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* CLID into packet */
|
/* CLID into packet */
|
||||||
for (p = daemon->packet, i = 0; i < data.clid_len; i++)
|
if (!is6)
|
||||||
|
for (p = daemon->packet, i = 0; i < data.clid_len; i++)
|
||||||
|
{
|
||||||
|
p += sprintf(p, "%.2x", buf[i]);
|
||||||
|
if (i != data.clid_len - 1)
|
||||||
|
p += sprintf(p, ":");
|
||||||
|
}
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
else
|
||||||
{
|
{
|
||||||
p += sprintf(p, "%.2x", buf[i]);
|
/* or IAID and server DUID for IPv6 */
|
||||||
if (i != data.clid_len - 1)
|
sprintf(daemon->dhcp_buff3, "%s%u", data.flags & LEASE_TA ? "T" : "", data.hwaddr_type);
|
||||||
p += sprintf(p, ":");
|
for (p = daemon->packet, i = 0; i < daemon->duid_len; i++)
|
||||||
|
{
|
||||||
|
p += sprintf(p, "%.2x", daemon->duid[i]);
|
||||||
|
if (i != daemon->duid_len - 1)
|
||||||
|
p += sprintf(p, ":");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* duid not MAC for IPv6 */
|
||||||
|
for (p = daemon->dhcp_buff, i = 0; i < data.clid_len; i++)
|
||||||
|
{
|
||||||
|
p += sprintf(p, "%.2x", buf[i]);
|
||||||
|
if (i != data.clid_len - 1)
|
||||||
|
p += sprintf(p, ":");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
buf += data.clid_len;
|
buf += data.clid_len;
|
||||||
|
|
||||||
@@ -242,96 +282,162 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
char *dot;
|
char *dot;
|
||||||
hostname = (char *)buf;
|
hostname = (char *)buf;
|
||||||
hostname[data.hostname_len - 1] = 0;
|
hostname[data.hostname_len - 1] = 0;
|
||||||
if (!legal_hostname(hostname))
|
if (data.action != ACTION_TFTP)
|
||||||
hostname = NULL;
|
|
||||||
else if ((dot = strchr(hostname, '.')))
|
|
||||||
{
|
{
|
||||||
domain = dot+1;
|
if (!legal_hostname(hostname))
|
||||||
*dot = 0;
|
hostname = NULL;
|
||||||
}
|
else if ((dot = strchr(hostname, '.')))
|
||||||
|
{
|
||||||
|
domain = dot+1;
|
||||||
|
*dot = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extradata = buf + data.hostname_len;
|
extradata = buf + data.hostname_len;
|
||||||
|
|
||||||
|
if (!is6)
|
||||||
|
inet_ntop(AF_INET, &data.addr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
else
|
||||||
|
inet_ntop(AF_INET6, &data.hwaddr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* file length */
|
||||||
|
if (data.action == ACTION_TFTP)
|
||||||
|
sprintf(daemon->dhcp_buff, "%u", data.hwaddr_len);
|
||||||
|
|
||||||
#ifdef HAVE_LUASCRIPT
|
#ifdef HAVE_LUASCRIPT
|
||||||
if (daemon->luascript)
|
if (daemon->luascript)
|
||||||
{
|
{
|
||||||
lua_getglobal(lua, "lease"); /* function to call */
|
if (data.action == ACTION_TFTP)
|
||||||
lua_pushstring(lua, action_str); /* arg1 - action */
|
|
||||||
lua_newtable(lua); /* arg2 - data table */
|
|
||||||
|
|
||||||
if (data.clid_len != 0)
|
|
||||||
{
|
{
|
||||||
lua_pushstring(lua, daemon->packet);
|
lua_getglobal(lua, "tftp");
|
||||||
lua_setfield(lua, -2, "client_id");
|
if (lua_type(lua, -1) != LUA_TFUNCTION)
|
||||||
|
lua_pop(lua, 1); /* tftp function optional */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, action_str); /* arg1 - action */
|
||||||
|
lua_newtable(lua); /* arg2 - data table */
|
||||||
|
lua_pushstring(lua, daemon->addrbuff);
|
||||||
|
lua_setfield(lua, -2, "destination_address");
|
||||||
|
lua_pushstring(lua, hostname);
|
||||||
|
lua_setfield(lua, -2, "file_name");
|
||||||
|
lua_pushstring(lua, daemon->dhcp_buff);
|
||||||
|
lua_setfield(lua, -2, "file_size");
|
||||||
|
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (strlen(data.interface) != 0)
|
|
||||||
{
|
{
|
||||||
lua_pushstring(lua, data.interface);
|
lua_getglobal(lua, "lease"); /* function to call */
|
||||||
lua_setfield(lua, -2, "interface");
|
lua_pushstring(lua, action_str); /* arg1 - action */
|
||||||
}
|
lua_newtable(lua); /* arg2 - data table */
|
||||||
|
|
||||||
|
if (is6)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, daemon->dhcp_buff);
|
||||||
|
lua_setfield(lua, -2, "client_duid");
|
||||||
|
lua_pushstring(lua, daemon->packet);
|
||||||
|
lua_setfield(lua, -2, "server_duid");
|
||||||
|
lua_pushstring(lua, daemon->dhcp_buff3);
|
||||||
|
lua_setfield(lua, -2, "iaid");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is6 && data.clid_len != 0)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, daemon->packet);
|
||||||
|
lua_setfield(lua, -2, "client_id");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(data.interface) != 0)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, data.interface);
|
||||||
|
lua_setfield(lua, -2, "interface");
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
lua_pushnumber(lua, data.length);
|
lua_pushnumber(lua, data.length);
|
||||||
lua_setfield(lua, -2, "lease_length");
|
lua_setfield(lua, -2, "lease_length");
|
||||||
#else
|
#else
|
||||||
lua_pushnumber(lua, data.expires);
|
lua_pushnumber(lua, data.expires);
|
||||||
lua_setfield(lua, -2, "lease_expires");
|
lua_setfield(lua, -2, "lease_expires");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (hostname)
|
if (hostname)
|
||||||
{
|
{
|
||||||
lua_pushstring(lua, hostname);
|
lua_pushstring(lua, hostname);
|
||||||
lua_setfield(lua, -2, "hostname");
|
lua_setfield(lua, -2, "hostname");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domain)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, domain);
|
||||||
|
lua_setfield(lua, -2, "domain");
|
||||||
|
}
|
||||||
|
|
||||||
|
end = extradata + data.ed_len;
|
||||||
|
buf = extradata;
|
||||||
|
|
||||||
|
if (!is6)
|
||||||
|
buf = grab_extradata_lua(buf, end, "vendor_class");
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
else
|
||||||
|
for (i = 0; i < data.hwaddr_len; i++)
|
||||||
|
{
|
||||||
|
sprintf(daemon->dhcp_buff2, "vendor_class%i", i);
|
||||||
|
buf = grab_extradata_lua(buf, end, daemon->dhcp_buff2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
buf = grab_extradata_lua(buf, end, "supplied_hostname");
|
||||||
|
|
||||||
|
if (!is6)
|
||||||
|
{
|
||||||
|
buf = grab_extradata_lua(buf, end, "cpewan_oui");
|
||||||
|
buf = grab_extradata_lua(buf, end, "cpewan_serial");
|
||||||
|
buf = grab_extradata_lua(buf, end, "cpewan_class");
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = grab_extradata_lua(buf, end, "tags");
|
||||||
|
|
||||||
|
if (is6)
|
||||||
|
buf = grab_extradata_lua(buf, end, "relay_address");
|
||||||
|
else if (data.giaddr.s_addr != 0)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, inet_ntoa(data.giaddr));
|
||||||
|
lua_setfield(lua, -2, "relay_address");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; buf; i++)
|
||||||
|
{
|
||||||
|
sprintf(daemon->dhcp_buff2, "user_class%i", i);
|
||||||
|
buf = grab_extradata_lua(buf, end, daemon->dhcp_buff2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
||||||
|
{
|
||||||
|
lua_pushnumber(lua, data.remaining_time);
|
||||||
|
lua_setfield(lua, -2, "time_remaining");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.action == ACTION_OLD_HOSTNAME && hostname)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, hostname);
|
||||||
|
lua_setfield(lua, -2, "old_hostname");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is6)
|
||||||
|
{
|
||||||
|
lua_pushstring(lua, daemon->dhcp_buff);
|
||||||
|
lua_setfield(lua, -2, "mac_address");
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pushstring(lua, daemon->addrbuff);
|
||||||
|
lua_setfield(lua, -2, "ip_address");
|
||||||
|
|
||||||
|
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (domain)
|
|
||||||
{
|
|
||||||
lua_pushstring(lua, domain);
|
|
||||||
lua_setfield(lua, -2, "domain");
|
|
||||||
}
|
|
||||||
|
|
||||||
end = extradata + data.ed_len;
|
|
||||||
buf = extradata;
|
|
||||||
buf = grab_extradata_lua(buf, end, "vendor_class");
|
|
||||||
buf = grab_extradata_lua(buf, end, "supplied_hostname");
|
|
||||||
buf = grab_extradata_lua(buf, end, "cpewan_oui");
|
|
||||||
buf = grab_extradata_lua(buf, end, "cpewan_serial");
|
|
||||||
buf = grab_extradata_lua(buf, end, "cpewan_class");
|
|
||||||
buf = grab_extradata_lua(buf, end, "tags");
|
|
||||||
|
|
||||||
for (i = 0; buf; i++)
|
|
||||||
{
|
|
||||||
sprintf(daemon->dhcp_buff2, "user_class%i", i);
|
|
||||||
buf = grab_extradata_lua(buf, end, daemon->dhcp_buff2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.giaddr.s_addr != 0)
|
|
||||||
{
|
|
||||||
lua_pushstring(lua, inet_ntoa(data.giaddr));
|
|
||||||
lua_setfield(lua, -2, "relay_address");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
|
||||||
{
|
|
||||||
lua_pushnumber(lua, data.remaining_time);
|
|
||||||
lua_setfield(lua, -2, "time_remaining");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.action == ACTION_OLD_HOSTNAME && hostname)
|
|
||||||
{
|
|
||||||
lua_pushstring(lua, hostname);
|
|
||||||
lua_setfield(lua, -2, "old_hostname");
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pushstring(lua, daemon->dhcp_buff);
|
|
||||||
lua_setfield(lua, -2, "mac_address");
|
|
||||||
|
|
||||||
lua_pushstring(lua, inet_ntoa(data.addr));
|
|
||||||
lua_setfield(lua, -2, "ip_address");
|
|
||||||
|
|
||||||
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -372,51 +478,87 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.clid_len != 0)
|
if (data.action != ACTION_TFTP)
|
||||||
my_setenv("DNSMASQ_CLIENT_ID", daemon->packet, &err);
|
{
|
||||||
|
if (is6)
|
||||||
if (strlen(data.interface) != 0)
|
{
|
||||||
my_setenv("DNSMASQ_INTERFACE", data.interface, &err);
|
my_setenv("DNSMASQ_IAID", daemon->dhcp_buff3, &err);
|
||||||
|
my_setenv("DNSMASQ_SERVER_DUID", daemon->packet, &err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is6 && data.clid_len != 0)
|
||||||
|
my_setenv("DNSMASQ_CLIENT_ID", daemon->packet, &err);
|
||||||
|
|
||||||
|
if (strlen(data.interface) != 0)
|
||||||
|
my_setenv("DNSMASQ_INTERFACE", data.interface, &err);
|
||||||
|
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
my_setenv("DNSMASQ_LEASE_LENGTH", daemon->dhcp_buff2, &err);
|
my_setenv("DNSMASQ_LEASE_LENGTH", daemon->dhcp_buff2, &err);
|
||||||
#else
|
#else
|
||||||
my_setenv("DNSMASQ_LEASE_EXPIRES", daemon->dhcp_buff2, &err);
|
my_setenv("DNSMASQ_LEASE_EXPIRES", daemon->dhcp_buff2, &err);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (domain)
|
if (domain)
|
||||||
my_setenv("DNSMASQ_DOMAIN", domain, &err);
|
my_setenv("DNSMASQ_DOMAIN", domain, &err);
|
||||||
|
|
||||||
end = extradata + data.ed_len;
|
end = extradata + data.ed_len;
|
||||||
buf = extradata;
|
buf = extradata;
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_VENDOR_CLASS", &err);
|
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_SUPPLIED_HOSTNAME", &err);
|
if (!is6)
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_CPEWAN_OUI", &err);
|
buf = grab_extradata(buf, end, "DNSMASQ_VENDOR_CLASS", &err);
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_CPEWAN_SERIAL", &err);
|
#ifdef HAVE_DHCP6
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_CPEWAN_CLASS", &err);
|
else
|
||||||
buf = grab_extradata(buf, end, "DNSMASQ_TAGS", &err);
|
{
|
||||||
|
if (data.hwaddr_len != 0)
|
||||||
for (i = 0; buf; i++)
|
{
|
||||||
{
|
buf = grab_extradata(buf, end, "DNSMASQ_VENDOR_CLASS_ID", &err);
|
||||||
sprintf(daemon->dhcp_buff2, "DNSMASQ_USER_CLASS%i", i);
|
for (i = 0; i < data.hwaddr_len - 1; i++)
|
||||||
buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err);
|
{
|
||||||
}
|
sprintf(daemon->dhcp_buff2, "DNSMASQ_VENDOR_CLASS%i", i);
|
||||||
|
buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err);
|
||||||
if (data.giaddr.s_addr != 0)
|
}
|
||||||
my_setenv("DNSMASQ_RELAY_ADDRESS", inet_ntoa(data.giaddr), &err);
|
}
|
||||||
|
}
|
||||||
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
#endif
|
||||||
{
|
|
||||||
sprintf(daemon->dhcp_buff2, "%u", data.remaining_time);
|
buf = grab_extradata(buf, end, "DNSMASQ_SUPPLIED_HOSTNAME", &err);
|
||||||
my_setenv("DNSMASQ_TIME_REMAINING", daemon->dhcp_buff2, &err);
|
|
||||||
}
|
if (!is6)
|
||||||
|
{
|
||||||
if (data.action == ACTION_OLD_HOSTNAME && hostname)
|
buf = grab_extradata(buf, end, "DNSMASQ_CPEWAN_OUI", &err);
|
||||||
{
|
buf = grab_extradata(buf, end, "DNSMASQ_CPEWAN_SERIAL", &err);
|
||||||
my_setenv("DNSMASQ_OLD_HOSTNAME", hostname, &err);
|
buf = grab_extradata(buf, end, "DNSMASQ_CPEWAN_CLASS", &err);
|
||||||
hostname = NULL;
|
}
|
||||||
|
|
||||||
|
buf = grab_extradata(buf, end, "DNSMASQ_TAGS", &err);
|
||||||
|
|
||||||
|
if (is6)
|
||||||
|
buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err);
|
||||||
|
else if (data.giaddr.s_addr != 0)
|
||||||
|
my_setenv("DNSMASQ_RELAY_ADDRESS", inet_ntoa(data.giaddr), &err);
|
||||||
|
|
||||||
|
for (i = 0; buf; i++)
|
||||||
|
{
|
||||||
|
sprintf(daemon->dhcp_buff2, "DNSMASQ_USER_CLASS%i", i);
|
||||||
|
buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.action != ACTION_DEL && data.remaining_time != 0)
|
||||||
|
{
|
||||||
|
sprintf(daemon->dhcp_buff2, "%u", data.remaining_time);
|
||||||
|
my_setenv("DNSMASQ_TIME_REMAINING", daemon->dhcp_buff2, &err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.action == ACTION_OLD_HOSTNAME && hostname)
|
||||||
|
{
|
||||||
|
my_setenv("DNSMASQ_OLD_HOSTNAME", hostname, &err);
|
||||||
|
hostname = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (option_bool(OPT_LOG_OPTS))
|
||||||
|
my_setenv("DNSMASQ_LOG_DHCP", "1", &err);
|
||||||
|
|
||||||
/* we need to have the event_fd around if exec fails */
|
/* we need to have the event_fd around if exec fails */
|
||||||
if ((i = fcntl(event_fd, F_GETFD)) != -1)
|
if ((i = fcntl(event_fd, F_GETFD)) != -1)
|
||||||
fcntl(event_fd, F_SETFD, i | FD_CLOEXEC);
|
fcntl(event_fd, F_SETFD, i | FD_CLOEXEC);
|
||||||
@@ -427,7 +569,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
|
|||||||
{
|
{
|
||||||
execl(daemon->lease_change_command,
|
execl(daemon->lease_change_command,
|
||||||
p ? p+1 : daemon->lease_change_command,
|
p ? p+1 : daemon->lease_change_command,
|
||||||
action_str, daemon->dhcp_buff, inet_ntoa(data.addr), hostname, (char*)NULL);
|
action_str, daemon->dhcp_buff, daemon->addrbuff, hostname, (char*)NULL);
|
||||||
err = errno;
|
err = errno;
|
||||||
}
|
}
|
||||||
/* failed, send event so the main process logs the problem */
|
/* failed, send event so the main process logs the problem */
|
||||||
@@ -487,26 +629,8 @@ static unsigned char *grab_extradata_lua(unsigned char *buf, unsigned char *end,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* pack up lease data into a buffer */
|
static void buff_alloc(size_t size)
|
||||||
void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t now)
|
|
||||||
{
|
{
|
||||||
unsigned char *p;
|
|
||||||
size_t size;
|
|
||||||
unsigned int hostname_len = 0, clid_len = 0, ed_len = 0;
|
|
||||||
|
|
||||||
/* no script */
|
|
||||||
if (daemon->helperfd == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (lease->extradata)
|
|
||||||
ed_len = lease->extradata_len;
|
|
||||||
if (lease->clid)
|
|
||||||
clid_len = lease->clid_len;
|
|
||||||
if (hostname)
|
|
||||||
hostname_len = strlen(hostname) + 1;
|
|
||||||
|
|
||||||
size = sizeof(struct script_data) + clid_len + ed_len + hostname_len;
|
|
||||||
|
|
||||||
if (size > buf_size)
|
if (size > buf_size)
|
||||||
{
|
{
|
||||||
struct script_data *new;
|
struct script_data *new;
|
||||||
@@ -522,8 +646,35 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
|
|||||||
buf = new;
|
buf = new;
|
||||||
buf_size = size;
|
buf_size = size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pack up lease data into a buffer */
|
||||||
|
void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t now)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
unsigned int hostname_len = 0, clid_len = 0, ed_len = 0;
|
||||||
|
int fd = daemon->dhcpfd;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (!daemon->dhcp)
|
||||||
|
fd = daemon->dhcp6fd;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* no script */
|
||||||
|
if (daemon->helperfd == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (lease->extradata)
|
||||||
|
ed_len = lease->extradata_len;
|
||||||
|
if (lease->clid)
|
||||||
|
clid_len = lease->clid_len;
|
||||||
|
if (hostname)
|
||||||
|
hostname_len = strlen(hostname) + 1;
|
||||||
|
|
||||||
|
buff_alloc(sizeof(struct script_data) + clid_len + ed_len + hostname_len);
|
||||||
|
|
||||||
buf->action = action;
|
buf->action = action;
|
||||||
|
buf->flags = lease->flags;
|
||||||
buf->hwaddr_len = lease->hwaddr_len;
|
buf->hwaddr_len = lease->hwaddr_len;
|
||||||
buf->hwaddr_type = lease->hwaddr_type;
|
buf->hwaddr_type = lease->hwaddr_type;
|
||||||
buf->clid_len = clid_len;
|
buf->clid_len = clid_len;
|
||||||
@@ -531,8 +682,8 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
|
|||||||
buf->hostname_len = hostname_len;
|
buf->hostname_len = hostname_len;
|
||||||
buf->addr = lease->addr;
|
buf->addr = lease->addr;
|
||||||
buf->giaddr = lease->giaddr;
|
buf->giaddr = lease->giaddr;
|
||||||
memcpy(buf->hwaddr, lease->hwaddr, lease->hwaddr_len);
|
memcpy(buf->hwaddr, lease->hwaddr, DHCP_CHADDR_MAX);
|
||||||
if (!indextoname(daemon->dhcpfd, lease->last_interface, buf->interface))
|
if (!indextoname(fd, lease->last_interface, buf->interface))
|
||||||
buf->interface[0] = 0;
|
buf->interface[0] = 0;
|
||||||
|
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
@@ -565,6 +716,37 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
|
|||||||
bytes_in_buf = p - (unsigned char *)buf;
|
bytes_in_buf = p - (unsigned char *)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_TFTP
|
||||||
|
/* This nastily re-uses DHCP-fields for TFTP stuff */
|
||||||
|
void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer)
|
||||||
|
{
|
||||||
|
unsigned int filename_len;
|
||||||
|
|
||||||
|
/* no script */
|
||||||
|
if (daemon->helperfd == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
filename_len = strlen(filename) + 1;
|
||||||
|
buff_alloc(sizeof(struct script_data) + filename_len);
|
||||||
|
memset(buf, 0, sizeof(struct script_data));
|
||||||
|
|
||||||
|
buf->action = ACTION_TFTP;
|
||||||
|
buf->hostname_len = filename_len;
|
||||||
|
buf->hwaddr_len = file_len;
|
||||||
|
|
||||||
|
if ((buf->flags = peer->sa.sa_family) == AF_INET)
|
||||||
|
buf->addr = peer->in.sin_addr;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else
|
||||||
|
memcpy(buf->hwaddr, &peer->in6.sin6_addr, IN6ADDRSZ);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memcpy((unsigned char *)(buf+1), filename, filename_len);
|
||||||
|
|
||||||
|
bytes_in_buf = sizeof(struct script_data) + filename_len;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int helper_buf_empty(void)
|
int helper_buf_empty(void)
|
||||||
{
|
{
|
||||||
return bytes_in_buf == 0;
|
return bytes_in_buf == 0;
|
||||||
|
|||||||
+415
-113
@@ -28,18 +28,9 @@ void lease_init(time_t now)
|
|||||||
struct dhcp_lease *lease;
|
struct dhcp_lease *lease;
|
||||||
int clid_len, hw_len, hw_type;
|
int clid_len, hw_len, hw_type;
|
||||||
FILE *leasestream;
|
FILE *leasestream;
|
||||||
#ifdef HAVE_DHCP6
|
|
||||||
int v6pass = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* These each hold a DHCP option max size 255
|
|
||||||
and get a terminating zero added */
|
|
||||||
daemon->dhcp_buff = safe_malloc(256);
|
|
||||||
daemon->dhcp_buff2 = safe_malloc(256);
|
|
||||||
daemon->dhcp_buff3 = safe_malloc(256);
|
|
||||||
|
|
||||||
leases_left = daemon->dhcp_max;
|
leases_left = daemon->dhcp_max;
|
||||||
|
|
||||||
if (option_bool(OPT_LEASE_RO))
|
if (option_bool(OPT_LEASE_RO))
|
||||||
{
|
{
|
||||||
/* run "<lease_change_script> init" once to get the
|
/* run "<lease_change_script> init" once to get the
|
||||||
@@ -73,45 +64,71 @@ void lease_init(time_t now)
|
|||||||
rewind(leasestream);
|
rewind(leasestream);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
|
||||||
again:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* client-id max length is 255 which is 255*2 digits + 254 colons
|
/* client-id max length is 255 which is 255*2 digits + 254 colons
|
||||||
borrow DNS packet buffer which is always larger than 1000 bytes */
|
borrow DNS packet buffer which is always larger than 1000 bytes */
|
||||||
if (leasestream)
|
if (leasestream)
|
||||||
while (fscanf(leasestream, "%lu %255s %64s %255s %764s",
|
while (fscanf(leasestream, "%255s %255s", daemon->dhcp_buff3, daemon->dhcp_buff2) == 2)
|
||||||
&ei, daemon->dhcp_buff2, daemon->namebuff,
|
|
||||||
daemon->dhcp_buff, daemon->packet) == 5)
|
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (!v6pass)
|
if (strcmp(daemon->dhcp_buff3, "duid") == 0)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
hw_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, DHCP_CHADDR_MAX, NULL, &hw_type);
|
daemon->duid_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, 130, NULL, NULL);
|
||||||
/* For backwards compatibility, no explict MAC address type means ether. */
|
daemon->duid = safe_malloc(daemon->duid_len);
|
||||||
if (hw_type == 0 && hw_len != 0)
|
memcpy(daemon->duid, daemon->dhcp_buff2, daemon->duid_len);
|
||||||
hw_type = ARPHRD_ETHER;
|
continue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
ei = atol(daemon->dhcp_buff3);
|
||||||
if (v6pass)
|
|
||||||
inet_pton(AF_INET6, daemon->namebuff, &addr.addr.addr6);
|
if (fscanf(leasestream, " %64s %255s %764s",
|
||||||
else
|
daemon->namebuff, daemon->dhcp_buff, daemon->packet) != 3)
|
||||||
#endif
|
break;
|
||||||
inet_pton(AF_INET, daemon->namebuff, &addr.addr.addr4);
|
|
||||||
|
|
||||||
clid_len = 0;
|
clid_len = 0;
|
||||||
if (strcmp(daemon->packet, "*") != 0)
|
if (strcmp(daemon->packet, "*") != 0)
|
||||||
clid_len = parse_hex(daemon->packet, (unsigned char *)daemon->packet, 255, NULL, NULL);
|
clid_len = parse_hex(daemon->packet, (unsigned char *)daemon->packet, 255, NULL, NULL);
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, daemon->namebuff, &addr.addr.addr4) &&
|
||||||
|
(lease = lease4_allocate(addr.addr.addr4)))
|
||||||
|
{
|
||||||
|
hw_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, DHCP_CHADDR_MAX, NULL, &hw_type);
|
||||||
|
/* For backwards compatibility, no explict MAC address type means ether. */
|
||||||
|
if (hw_type == 0 && hw_len != 0)
|
||||||
|
hw_type = ARPHRD_ETHER;
|
||||||
|
|
||||||
|
lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet,
|
||||||
|
hw_len, hw_type, clid_len, now, 0);
|
||||||
|
|
||||||
|
if (strcmp(daemon->dhcp_buff, "*") != 0)
|
||||||
|
lease_set_hostname(lease, daemon->dhcp_buff, 0, get_domain(lease->addr), NULL);
|
||||||
|
}
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (v6pass)
|
else if (inet_pton(AF_INET6, daemon->namebuff, &addr.addr.addr6))
|
||||||
lease = lease_allocate6(&addr.addr.addr6);
|
{
|
||||||
else
|
char *s = daemon->dhcp_buff2;
|
||||||
|
int lease_type = LEASE_NA;
|
||||||
|
|
||||||
|
if (s[0] == 'T')
|
||||||
|
{
|
||||||
|
lease_type = LEASE_TA;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
hw_type = atoi(s);
|
||||||
|
|
||||||
|
if ((lease = lease6_allocate(&addr.addr.addr6, lease_type)))
|
||||||
|
{
|
||||||
|
lease_set_hwaddr(lease, NULL, (unsigned char *)daemon->packet, 0, hw_type, clid_len, now, 0);
|
||||||
|
|
||||||
|
if (strcmp(daemon->dhcp_buff, "*") != 0)
|
||||||
|
lease_set_hostname(lease, daemon->dhcp_buff, 0, get_domain6((struct in6_addr *)lease->hwaddr), NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
lease = lease_allocate4(addr.addr.addr4);
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
if (!lease)
|
if (!lease)
|
||||||
die (_("too many stored leases"), NULL, EC_MISC);
|
die (_("too many stored leases"), NULL, EC_MISC);
|
||||||
|
|
||||||
@@ -126,37 +143,11 @@ void lease_init(time_t now)
|
|||||||
even when sizeof(time_t) == 8 */
|
even when sizeof(time_t) == 8 */
|
||||||
lease->expires = (time_t)ei;
|
lease->expires = (time_t)ei;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
|
||||||
if (!v6pass)
|
|
||||||
#endif
|
|
||||||
lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet, hw_len, hw_type, clid_len);
|
|
||||||
|
|
||||||
if (strcmp(daemon->dhcp_buff, "*") != 0)
|
|
||||||
lease_set_hostname(lease, daemon->dhcp_buff, 0);
|
|
||||||
|
|
||||||
/* set these correctly: the "old" events are generated later from
|
/* set these correctly: the "old" events are generated later from
|
||||||
the startup synthesised SIGHUP. */
|
the startup synthesised SIGHUP. */
|
||||||
lease->new = lease->changed = 0;
|
lease->flags &= ~(LEASE_NEW | LEASE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
|
||||||
if (!v6pass)
|
|
||||||
{
|
|
||||||
if (fscanf(leasestream, "duid %255s", daemon->dhcp_buff) == 1)
|
|
||||||
{
|
|
||||||
daemon->duid_len = parse_hex(daemon->dhcp_buff, (unsigned char *)daemon->dhcp_buff, 130, NULL, NULL);
|
|
||||||
daemon->duid = safe_malloc(daemon->duid_len);
|
|
||||||
memcpy(daemon->duid, daemon->dhcp_buff, daemon->duid_len );
|
|
||||||
v6pass = 1;
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */
|
|
||||||
if (daemon->dhcp6)
|
|
||||||
make_duid(now);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SCRIPT
|
#ifdef HAVE_SCRIPT
|
||||||
if (!daemon->lease_stream)
|
if (!daemon->lease_stream)
|
||||||
@@ -194,17 +185,17 @@ void lease_update_from_configs(void)
|
|||||||
struct dhcp_lease *lease;
|
struct dhcp_lease *lease;
|
||||||
struct dhcp_config *config;
|
struct dhcp_config *config;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len,
|
if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len,
|
||||||
lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) &&
|
lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) &&
|
||||||
(config->flags & CONFIG_NAME) &&
|
(config->flags & CONFIG_NAME) &&
|
||||||
(!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr))
|
(!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr))
|
||||||
lease_set_hostname(lease, config->hostname, 1);
|
lease_set_hostname(lease, config->hostname, 1, get_domain(lease->addr), NULL);
|
||||||
else if ((name = host_from_dns(lease->addr)))
|
else if ((name = host_from_dns(lease->addr)))
|
||||||
lease_set_hostname(lease, name, 1); /* updates auth flag only */
|
lease_set_hostname(lease, name, 1, get_domain(lease->addr), NULL); /* updates auth flag only */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ourprintf(int *errp, char *format, ...)
|
static void ourprintf(int *errp, char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@@ -232,7 +223,7 @@ void lease_update_file(time_t now)
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (lease->is_ipv6)
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -277,7 +268,7 @@ void lease_update_file(time_t now)
|
|||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!lease->is_ipv6)
|
if (!(lease->flags & (LEASE_TA | LEASE_NA)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
@@ -288,7 +279,8 @@ void lease_update_file(time_t now)
|
|||||||
|
|
||||||
inet_ntop(AF_INET6, lease->hwaddr, daemon->addrbuff, ADDRSTRLEN);
|
inet_ntop(AF_INET6, lease->hwaddr, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
|
||||||
ourprintf(&err, "* %s ", daemon->addrbuff);
|
ourprintf(&err, "%s%u %s ", (lease->flags & LEASE_TA) ? "T" : "",
|
||||||
|
lease->hwaddr_type, daemon->addrbuff);
|
||||||
ourprintf(&err, "%s ", lease->hostname ? lease->hostname : "*");
|
ourprintf(&err, "%s ", lease->hostname ? lease->hostname : "*");
|
||||||
|
|
||||||
if (lease->clid && lease->clid_len != 0)
|
if (lease->clid && lease->clid_len != 0)
|
||||||
@@ -312,7 +304,29 @@ void lease_update_file(time_t now)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set alarm for when the first lease expires + slop. */
|
/* Set alarm for when the first lease expires + slop. */
|
||||||
for (next_event = 0, lease = leases; lease; lease = lease->next)
|
next_event = 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
/* do timed RAs and determine when the next is, also pings to potential SLAAC addresses */
|
||||||
|
if (daemon->doing_ra)
|
||||||
|
{
|
||||||
|
time_t event;
|
||||||
|
|
||||||
|
if ((event = periodic_slaac(now, leases)) != 0)
|
||||||
|
{
|
||||||
|
if (next_event == 0 || difftime(next_event, event) > 0.0)
|
||||||
|
next_event = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((event = periodic_ra(now)) != 0)
|
||||||
|
{
|
||||||
|
if (next_event == 0 || difftime(next_event, event) > 0.0)
|
||||||
|
next_event = event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
if (lease->expires != 0 &&
|
if (lease->expires != 0 &&
|
||||||
(next_event == 0 || difftime(next_event, lease->expires + 10) > 0.0))
|
(next_event == 0 || difftime(next_event, lease->expires + 10) > 0.0))
|
||||||
next_event = lease->expires + 10;
|
next_event = lease->expires + 10;
|
||||||
@@ -327,25 +341,122 @@ void lease_update_file(time_t now)
|
|||||||
(unsigned int)difftime(next_event, now));
|
(unsigned int)difftime(next_event, now));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next_event != 0)
|
send_alarm(next_event, now);
|
||||||
alarm((unsigned)difftime(next_event, now));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lease_update_dns(void)
|
|
||||||
|
static int find_interface_v4(struct in_addr local, int if_index,
|
||||||
|
struct in_addr netmask, struct in_addr broadcast, void *vparam)
|
||||||
{
|
{
|
||||||
struct dhcp_lease *lease;
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
if (daemon->port != 0 && dns_dirty)
|
(void) broadcast;
|
||||||
|
(void) vparam;
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
if (!(lease->flags & (LEASE_TA | LEASE_NA)))
|
||||||
|
if (is_same_net(local, lease->addr, netmask))
|
||||||
|
lease_set_interface(lease, if_index, *((time_t *)vparam));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
static int find_interface_v6(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
|
(void)scope;
|
||||||
|
(void)dad;
|
||||||
|
(void)preferred;
|
||||||
|
(void)valid;
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
if ((lease->flags & (LEASE_TA | LEASE_NA)))
|
||||||
|
if (is_same_net6(local, (struct in6_addr *)&lease->hwaddr, prefix))
|
||||||
|
lease_set_interface(lease, if_index, *((time_t *)vparam));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lease_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface)
|
||||||
|
{
|
||||||
|
/* We may be doing RA but not DHCPv4, in which case the lease
|
||||||
|
database may not exist and we have nothing to do anyway */
|
||||||
|
if (daemon->dhcp)
|
||||||
|
slaac_ping_reply(sender, packet, interface, leases);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Find interfaces associated with leases at start-up. This gets updated as
|
||||||
|
we do DHCP transactions, but information about directly-connected subnets
|
||||||
|
is useful from scrips and necessary for determining SLAAC addresses from
|
||||||
|
start-time. */
|
||||||
|
void lease_find_interfaces(time_t now)
|
||||||
|
{
|
||||||
|
iface_enumerate(AF_INET, &now, find_interface_v4);
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
iface_enumerate(AF_INET6, &now, find_interface_v6);
|
||||||
|
|
||||||
|
/* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */
|
||||||
|
if (!daemon->duid && daemon->dhcp6)
|
||||||
{
|
{
|
||||||
cache_unhash_dhcp();
|
file_dirty = 1;
|
||||||
|
make_duid(now);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void lease_update_dns(int force)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
|
if (daemon->port != 0 && (dns_dirty || force))
|
||||||
|
{
|
||||||
|
#ifndef HAVE_BROKEN_RTC
|
||||||
|
/* force transfer to authoritative secondaries */
|
||||||
|
daemon->soa_sn++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cache_unhash_dhcp();
|
||||||
|
|
||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
|
int prot = AF_INET;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
|
prot = AF_INET6;
|
||||||
|
else if (lease->hostname || lease->fqdn)
|
||||||
|
{
|
||||||
|
struct slaac_address *slaac;
|
||||||
|
|
||||||
|
for (slaac = lease->slaac_address; slaac; slaac = slaac->next)
|
||||||
|
if (slaac->backoff == 0)
|
||||||
|
{
|
||||||
|
if (lease->fqdn)
|
||||||
|
cache_add_dhcp_entry(lease->fqdn, AF_INET6, (struct all_addr *)&slaac->addr, lease->expires);
|
||||||
|
if (!option_bool(OPT_DHCP_FQDN) && lease->hostname)
|
||||||
|
cache_add_dhcp_entry(lease->hostname, AF_INET6, (struct all_addr *)&slaac->addr, lease->expires);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (lease->fqdn)
|
if (lease->fqdn)
|
||||||
cache_add_dhcp_entry(lease->fqdn, &lease->addr, lease->expires);
|
cache_add_dhcp_entry(lease->fqdn, prot,
|
||||||
|
prot == AF_INET ? (struct all_addr *)&lease->addr : (struct all_addr *)&lease->hwaddr,
|
||||||
|
lease->expires);
|
||||||
|
|
||||||
if (!option_bool(OPT_DHCP_FQDN) && lease->hostname)
|
if (!option_bool(OPT_DHCP_FQDN) && lease->hostname)
|
||||||
cache_add_dhcp_entry(lease->hostname, &lease->addr, lease->expires);
|
cache_add_dhcp_entry(lease->hostname, prot,
|
||||||
|
prot == AF_INET ? (struct all_addr *)&lease->addr : (struct all_addr *)&lease->hwaddr,
|
||||||
|
lease->expires);
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_dirty = 0;
|
dns_dirty = 0;
|
||||||
@@ -389,7 +500,7 @@ struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int h
|
|||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (lease->is_ipv6)
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
if (lease->clid && clid_len == lease->clid_len &&
|
if (lease->clid && clid_len == lease->clid_len &&
|
||||||
@@ -400,7 +511,7 @@ struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int h
|
|||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (lease->is_ipv6)
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
if ((!lease->clid || !clid) &&
|
if ((!lease->clid || !clid) &&
|
||||||
@@ -421,7 +532,7 @@ struct dhcp_lease *lease_find_by_addr(struct in_addr addr)
|
|||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (lease->is_ipv6)
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
if (lease->addr.s_addr == addr.s_addr)
|
if (lease->addr.s_addr == addr.s_addr)
|
||||||
@@ -431,6 +542,96 @@ struct dhcp_lease *lease_find_by_addr(struct in_addr addr)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
/* addr or clid may be NULL for "don't care, both NULL resets "USED" flags both
|
||||||
|
set activates USED check */
|
||||||
|
struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len,
|
||||||
|
int lease_type, int iaid, struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
{
|
||||||
|
if (!(lease->flags & lease_type) || lease->hwaddr_type != iaid)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (clid && addr && (lease->flags & LEASE_USED))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (addr && memcmp(lease->hwaddr, addr, IN6ADDRSZ) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (clid &&
|
||||||
|
(clid_len != lease->clid_len ||
|
||||||
|
memcmp(clid, lease->clid, clid_len) != 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
lease->flags |= LEASE_USED;
|
||||||
|
return lease;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lease6_filter(int lease_type, int iaid, struct dhcp_context *context)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
{
|
||||||
|
/* reset "USED flag */
|
||||||
|
lease->flags &= ~LEASE_USED;
|
||||||
|
|
||||||
|
if (!(lease->flags & lease_type) || lease->hwaddr_type != iaid)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* leases on the wrong interface get filtered out here */
|
||||||
|
if (!is_addr_in_context6(context, (struct in6_addr *)&lease->hwaddr))
|
||||||
|
lease->flags |= LEASE_USED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dhcp_lease *lease6_find_by_addr(struct in6_addr *net, int prefix, u64 addr)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
{
|
||||||
|
if (!(lease->flags & (LEASE_TA | LEASE_NA)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (is_same_net6((struct in6_addr *)lease->hwaddr, net, prefix) &&
|
||||||
|
(prefix == 128 || addr6part((struct in6_addr *)lease->hwaddr) == addr))
|
||||||
|
return lease;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find largest assigned address in context */
|
||||||
|
u64 lease_find_max_addr6(struct dhcp_context *context)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
u64 addr = addr6part(&context->start6);
|
||||||
|
|
||||||
|
if (!(context->flags & (CONTEXT_STATIC | CONTEXT_PROXY)))
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
{
|
||||||
|
if (!(lease->flags & (LEASE_TA | LEASE_NA)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (is_same_net6((struct in6_addr *)lease->hwaddr, &context->start6, 64) &&
|
||||||
|
addr6part((struct in6_addr *)lease->hwaddr) > addr6part(&context->start6) &&
|
||||||
|
addr6part((struct in6_addr *)lease->hwaddr) <= addr6part(&context->end6) &&
|
||||||
|
addr6part((struct in6_addr *)lease->hwaddr) > addr)
|
||||||
|
addr = addr6part((struct in6_addr *)lease->hwaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Find largest assigned address in context */
|
/* Find largest assigned address in context */
|
||||||
struct in_addr lease_find_max_addr(struct dhcp_context *context)
|
struct in_addr lease_find_max_addr(struct dhcp_context *context)
|
||||||
{
|
{
|
||||||
@@ -441,7 +642,7 @@ struct in_addr lease_find_max_addr(struct dhcp_context *context)
|
|||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (lease->is_ipv6)
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
if (((unsigned)ntohl(lease->addr.s_addr)) > ((unsigned)ntohl(context->start.s_addr)) &&
|
if (((unsigned)ntohl(lease->addr.s_addr)) > ((unsigned)ntohl(context->start.s_addr)) &&
|
||||||
@@ -460,7 +661,7 @@ static struct dhcp_lease *lease_allocate(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(lease, 0, sizeof(struct dhcp_lease));
|
memset(lease, 0, sizeof(struct dhcp_lease));
|
||||||
lease->new = 1;
|
lease->flags = LEASE_NEW;
|
||||||
lease->expires = 1;
|
lease->expires = 1;
|
||||||
#ifdef HAVE_BROKEN_RTC
|
#ifdef HAVE_BROKEN_RTC
|
||||||
lease->length = 0xffffffff; /* illegal value */
|
lease->length = 0xffffffff; /* illegal value */
|
||||||
@@ -474,7 +675,7 @@ static struct dhcp_lease *lease_allocate(void)
|
|||||||
return lease;
|
return lease;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dhcp_lease *lease_allocate4(struct in_addr addr)
|
struct dhcp_lease *lease4_allocate(struct in_addr addr)
|
||||||
{
|
{
|
||||||
struct dhcp_lease *lease = lease_allocate();
|
struct dhcp_lease *lease = lease_allocate();
|
||||||
lease->addr = addr;
|
lease->addr = addr;
|
||||||
@@ -484,11 +685,11 @@ struct dhcp_lease *lease_allocate4(struct in_addr addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
struct dhcp_lease *lease_allocate6(struct in6_addr *addrp)
|
struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type)
|
||||||
{
|
{
|
||||||
struct dhcp_lease *lease = lease_allocate();
|
struct dhcp_lease *lease = lease_allocate();
|
||||||
memcpy(lease->hwaddr, addrp, sizeof(*addrp)) ;
|
memcpy(lease->hwaddr, addrp, sizeof(*addrp)) ;
|
||||||
lease->is_ipv6 = 1;
|
lease->flags |= lease_type;
|
||||||
|
|
||||||
return lease;
|
return lease;
|
||||||
}
|
}
|
||||||
@@ -509,7 +710,8 @@ void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now)
|
|||||||
dns_dirty = 1;
|
dns_dirty = 1;
|
||||||
lease->expires = exp;
|
lease->expires = exp;
|
||||||
#ifndef HAVE_BROKEN_RTC
|
#ifndef HAVE_BROKEN_RTC
|
||||||
lease->aux_changed = file_dirty = 1;
|
lease->flags |= LEASE_AUX_CHANGED;
|
||||||
|
file_dirty = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,22 +719,36 @@ void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now)
|
|||||||
if (len != lease->length)
|
if (len != lease->length)
|
||||||
{
|
{
|
||||||
lease->length = len;
|
lease->length = len;
|
||||||
lease->aux_changed = file_dirty = 1;
|
lease->flags |= LEASE_AUX_CHANGED;
|
||||||
|
file_dirty = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
|
void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
|
||||||
unsigned char *clid, int hw_len, int hw_type, int clid_len)
|
unsigned char *clid, int hw_len, int hw_type, int clid_len,
|
||||||
|
time_t now, int force)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
int change = force;
|
||||||
|
lease->flags |= LEASE_HAVE_HWADDR;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
(void)force;
|
||||||
|
|
||||||
if (hw_len != lease->hwaddr_len ||
|
if (hw_len != lease->hwaddr_len ||
|
||||||
hw_type != lease->hwaddr_type ||
|
hw_type != lease->hwaddr_type ||
|
||||||
(hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
|
(hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
|
||||||
{
|
{
|
||||||
memcpy(lease->hwaddr, hwaddr, hw_len);
|
if (hw_len != 0)
|
||||||
|
memcpy(lease->hwaddr, hwaddr, hw_len);
|
||||||
lease->hwaddr_len = hw_len;
|
lease->hwaddr_len = hw_len;
|
||||||
lease->hwaddr_type = hw_type;
|
lease->hwaddr_type = hw_type;
|
||||||
lease->changed = file_dirty = 1; /* run script on change */
|
lease->flags |= LEASE_CHANGED;
|
||||||
|
file_dirty = 1; /* run script on change */
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
change = 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only update clid when one is available, stops packets
|
/* only update clid when one is available, stops packets
|
||||||
@@ -545,18 +761,32 @@ void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
|
|||||||
|
|
||||||
if (lease->clid_len != clid_len)
|
if (lease->clid_len != clid_len)
|
||||||
{
|
{
|
||||||
lease->aux_changed = file_dirty = 1;
|
lease->flags |= LEASE_AUX_CHANGED;
|
||||||
|
file_dirty = 1;
|
||||||
free(lease->clid);
|
free(lease->clid);
|
||||||
if (!(lease->clid = whine_malloc(clid_len)))
|
if (!(lease->clid = whine_malloc(clid_len)))
|
||||||
return;
|
return;
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
change = 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (memcmp(lease->clid, clid, clid_len) != 0)
|
else if (memcmp(lease->clid, clid, clid_len) != 0)
|
||||||
lease->aux_changed = file_dirty = 1;
|
{
|
||||||
|
lease->flags |= LEASE_AUX_CHANGED;
|
||||||
|
file_dirty = 1;
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
change = 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
lease->clid_len = clid_len;
|
lease->clid_len = clid_len;
|
||||||
memcpy(lease->clid, clid, clid_len);
|
memcpy(lease->clid, clid, clid_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (change)
|
||||||
|
slaac_add_addrs(lease, now, force);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kill_name(struct dhcp_lease *lease)
|
static void kill_name(struct dhcp_lease *lease)
|
||||||
@@ -568,7 +798,7 @@ static void kill_name(struct dhcp_lease *lease)
|
|||||||
free(lease->old_hostname);
|
free(lease->old_hostname);
|
||||||
|
|
||||||
/* If we know the fqdn, pass that. The helper will derive the
|
/* If we know the fqdn, pass that. The helper will derive the
|
||||||
unqualified name from it, free the unqulaified name here. */
|
unqualified name from it, free the unqualified name here. */
|
||||||
|
|
||||||
if (lease->fqdn)
|
if (lease->fqdn)
|
||||||
{
|
{
|
||||||
@@ -581,14 +811,18 @@ static void kill_name(struct dhcp_lease *lease)
|
|||||||
lease->hostname = lease->fqdn = NULL;
|
lease->hostname = lease->fqdn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth)
|
void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth, char *domain, char *config_domain)
|
||||||
{
|
{
|
||||||
struct dhcp_lease *lease_tmp;
|
struct dhcp_lease *lease_tmp;
|
||||||
char *new_name = NULL, *new_fqdn = NULL;
|
char *new_name = NULL, *new_fqdn = NULL;
|
||||||
|
|
||||||
|
if (config_domain && (!domain || !hostname_isequal(domain, config_domain)))
|
||||||
|
my_syslog(MS_DHCP | LOG_WARNING, _("Ignoring domain %s for DHCP host name %s"), config_domain, name);
|
||||||
|
|
||||||
if (lease->hostname && name && hostname_isequal(lease->hostname, name))
|
if (lease->hostname && name && hostname_isequal(lease->hostname, name))
|
||||||
{
|
{
|
||||||
lease->auth_name = auth;
|
if (auth)
|
||||||
|
lease->flags |= LEASE_AUTH_NAME;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,19 +832,21 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth)
|
|||||||
/* If a machine turns up on a new net without dropping the old lease,
|
/* If a machine turns up on a new net without dropping the old lease,
|
||||||
or two machines claim the same name, then we end up with two interfaces with
|
or two machines claim the same name, then we end up with two interfaces with
|
||||||
the same name. Check for that here and remove the name from the old lease.
|
the same name. Check for that here and remove the name from the old lease.
|
||||||
|
Note that IPv6 leases are different. All the leases to the same DUID are
|
||||||
|
allowed the same name.
|
||||||
|
|
||||||
Don't allow a name from the client to override a name from dnsmasq config. */
|
Don't allow a name from the client to override a name from dnsmasq config. */
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
{
|
{
|
||||||
if ((new_name = whine_malloc(strlen(name) + 1)))
|
if ((new_name = whine_malloc(strlen(name) + 1)))
|
||||||
{
|
{
|
||||||
char *suffix = get_domain(lease->addr);
|
|
||||||
strcpy(new_name, name);
|
strcpy(new_name, name);
|
||||||
if (suffix && (new_fqdn = whine_malloc(strlen(new_name) + strlen(suffix) + 2)))
|
if (domain && (new_fqdn = whine_malloc(strlen(new_name) + strlen(domain) + 2)))
|
||||||
{
|
{
|
||||||
strcpy(new_fqdn, name);
|
strcpy(new_fqdn, name);
|
||||||
strcat(new_fqdn, ".");
|
strcat(new_fqdn, ".");
|
||||||
strcat(new_fqdn, suffix);
|
strcat(new_fqdn, domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,7 +855,7 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth)
|
|||||||
{
|
{
|
||||||
if (option_bool(OPT_DHCP_FQDN))
|
if (option_bool(OPT_DHCP_FQDN))
|
||||||
{
|
{
|
||||||
if (!new_fqdn || !lease_tmp->fqdn || !hostname_isequal(lease_tmp->fqdn, new_fqdn) )
|
if (!new_fqdn || !lease_tmp->fqdn || !hostname_isequal(lease_tmp->fqdn, new_fqdn))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -627,8 +863,22 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth)
|
|||||||
if (!new_name || !lease_tmp->hostname || !hostname_isequal(lease_tmp->hostname, new_name) )
|
if (!new_name || !lease_tmp->hostname || !hostname_isequal(lease_tmp->hostname, new_name) )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lease_tmp->auth_name && !auth)
|
if (lease->flags & (LEASE_TA | LEASE_NA))
|
||||||
|
{
|
||||||
|
if (!(lease_tmp->flags & (LEASE_TA | LEASE_NA)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* another lease for the same DUID is OK for IPv6 */
|
||||||
|
if (lease->clid_len == lease_tmp->clid_len &&
|
||||||
|
lease->clid && lease_tmp->clid &&
|
||||||
|
memcmp(lease->clid, lease_tmp->clid, lease->clid_len) == 0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (lease_tmp->flags & (LEASE_TA | LEASE_NA))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((lease_tmp->flags & LEASE_AUTH_NAME) && !auth)
|
||||||
{
|
{
|
||||||
free(new_name);
|
free(new_name);
|
||||||
free(new_fqdn);
|
free(new_fqdn);
|
||||||
@@ -645,20 +895,26 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth)
|
|||||||
|
|
||||||
lease->hostname = new_name;
|
lease->hostname = new_name;
|
||||||
lease->fqdn = new_fqdn;
|
lease->fqdn = new_fqdn;
|
||||||
lease->auth_name = auth;
|
|
||||||
|
if (auth)
|
||||||
|
lease->flags |= LEASE_AUTH_NAME;
|
||||||
|
|
||||||
file_dirty = 1;
|
file_dirty = 1;
|
||||||
dns_dirty = 1;
|
dns_dirty = 1;
|
||||||
lease->changed = 1; /* run script on change */
|
lease->flags |= LEASE_CHANGED; /* run script on change */
|
||||||
}
|
}
|
||||||
|
|
||||||
void lease_set_interface(struct dhcp_lease *lease, int interface)
|
void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now)
|
||||||
{
|
{
|
||||||
if (lease->last_interface == interface)
|
if (lease->last_interface == interface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lease->last_interface = interface;
|
lease->last_interface = interface;
|
||||||
lease->changed = 1;
|
lease->flags |= LEASE_CHANGED;
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
slaac_add_addrs(lease, now, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void rerun_scripts(void)
|
void rerun_scripts(void)
|
||||||
@@ -666,7 +922,7 @@ void rerun_scripts(void)
|
|||||||
struct dhcp_lease *lease;
|
struct dhcp_lease *lease;
|
||||||
|
|
||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
lease->changed = 1;
|
lease->flags |= LEASE_CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* deleted leases get transferred to the old_leases list.
|
/* deleted leases get transferred to the old_leases list.
|
||||||
@@ -701,6 +957,14 @@ int do_script_run(time_t now)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
struct slaac_address *slaac, *tmp;
|
||||||
|
for (slaac = lease->slaac_address; slaac; slaac = tmp)
|
||||||
|
{
|
||||||
|
tmp = slaac->next;
|
||||||
|
free(slaac);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
kill_name(lease);
|
kill_name(lease);
|
||||||
#ifdef HAVE_SCRIPT
|
#ifdef HAVE_SCRIPT
|
||||||
queue_script(ACTION_DEL, lease, lease->old_hostname, now);
|
queue_script(ACTION_DEL, lease, lease->old_hostname, now);
|
||||||
@@ -732,18 +996,18 @@ int do_script_run(time_t now)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (lease = leases; lease; lease = lease->next)
|
for (lease = leases; lease; lease = lease->next)
|
||||||
if (lease->new || lease->changed ||
|
if ((lease->flags & (LEASE_NEW | LEASE_CHANGED)) ||
|
||||||
(lease->aux_changed && option_bool(OPT_LEASE_RO)))
|
((lease->flags & LEASE_AUX_CHANGED) && option_bool(OPT_LEASE_RO)))
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SCRIPT
|
#ifdef HAVE_SCRIPT
|
||||||
queue_script(lease->new ? ACTION_ADD : ACTION_OLD, lease,
|
queue_script((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease,
|
||||||
lease->fqdn ? lease->fqdn : lease->hostname, now);
|
lease->fqdn ? lease->fqdn : lease->hostname, now);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
emit_dbus_signal(lease->new ? ACTION_ADD : ACTION_OLD, lease,
|
emit_dbus_signal((lease->flags & LEASE_NEW) ? ACTION_ADD : ACTION_OLD, lease,
|
||||||
lease->fqdn ? lease->fqdn : lease->hostname);
|
lease->fqdn ? lease->fqdn : lease->hostname);
|
||||||
#endif
|
#endif
|
||||||
lease->new = lease->changed = lease->aux_changed = 0;
|
lease->flags &= ~(LEASE_NEW | LEASE_CHANGED | LEASE_AUX_CHANGED);
|
||||||
|
|
||||||
/* this is used for the "add" call, then junked, since they're not in the database */
|
/* this is used for the "add" call, then junked, since they're not in the database */
|
||||||
free(lease->extradata);
|
free(lease->extradata);
|
||||||
@@ -755,6 +1019,44 @@ int do_script_run(time_t now)
|
|||||||
return 0; /* nothing to do */
|
return 0; /* nothing to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_SCRIPT
|
||||||
|
void lease_add_extradata(struct dhcp_lease *lease, unsigned char *data, unsigned int len, int delim)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
/* check for embeded NULLs */
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
if (data[i] == 0)
|
||||||
|
{
|
||||||
|
len = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lease->extradata_size - lease->extradata_len) < (len + 1))
|
||||||
|
{
|
||||||
|
size_t newsz = lease->extradata_len + len + 100;
|
||||||
|
unsigned char *new = whine_malloc(newsz);
|
||||||
|
|
||||||
|
if (!new)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (lease->extradata)
|
||||||
|
{
|
||||||
|
memcpy(new, lease->extradata, lease->extradata_len);
|
||||||
|
free(lease->extradata);
|
||||||
|
}
|
||||||
|
|
||||||
|
lease->extradata = new;
|
||||||
|
lease->extradata_size = newsz;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len != 0)
|
||||||
|
memcpy(lease->extradata + lease->extradata_len, data, len);
|
||||||
|
lease->extradata[lease->extradata_len + len] = delim;
|
||||||
|
lease->extradata_len += len + 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+125
-68
@@ -38,8 +38,7 @@
|
|||||||
static struct iovec iov;
|
static struct iovec iov;
|
||||||
static u32 netlink_pid;
|
static u32 netlink_pid;
|
||||||
|
|
||||||
static void nl_err(struct nlmsghdr *h);
|
static int nl_async(struct nlmsghdr *h);
|
||||||
static void nl_routechange(struct nlmsghdr *h);
|
|
||||||
|
|
||||||
void netlink_init(void)
|
void netlink_init(void)
|
||||||
{
|
{
|
||||||
@@ -49,10 +48,17 @@ void netlink_init(void)
|
|||||||
addr.nl_family = AF_NETLINK;
|
addr.nl_family = AF_NETLINK;
|
||||||
addr.nl_pad = 0;
|
addr.nl_pad = 0;
|
||||||
addr.nl_pid = 0; /* autobind */
|
addr.nl_pid = 0; /* autobind */
|
||||||
#ifdef HAVE_IPV6
|
|
||||||
addr.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE;
|
|
||||||
#else
|
|
||||||
addr.nl_groups = RTMGRP_IPV4_ROUTE;
|
addr.nl_groups = RTMGRP_IPV4_ROUTE;
|
||||||
|
if (option_bool(OPT_CLEVERBIND))
|
||||||
|
addr.nl_groups |= RTMGRP_IPV4_IFADDR;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
addr.nl_groups |= RTMGRP_IPV6_ROUTE;
|
||||||
|
if (option_bool(OPT_CLEVERBIND))
|
||||||
|
addr.nl_groups |= RTMGRP_IPV6_IFADDR;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_ra || daemon->doing_dhcp6)
|
||||||
|
addr.nl_groups |= RTMGRP_IPV6_IFADDR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* May not be able to have permission to set multicast groups don't die in that case */
|
/* May not be able to have permission to set multicast groups don't die in that case */
|
||||||
@@ -136,6 +142,7 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
struct nlmsghdr *h;
|
struct nlmsghdr *h;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
static unsigned int seq = 0;
|
static unsigned int seq = 0;
|
||||||
|
int callback_ok = 1, newaddr = 0;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
struct nlmsghdr nlh;
|
struct nlmsghdr nlh;
|
||||||
@@ -181,12 +188,36 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
|
for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
|
||||||
if (h->nlmsg_seq != seq || h->nlmsg_pid != netlink_pid)
|
if (h->nlmsg_seq != seq || h->nlmsg_pid != netlink_pid || h->nlmsg_type == NLMSG_ERROR)
|
||||||
nl_routechange(h); /* May be multicast arriving async */
|
{
|
||||||
else if (h->nlmsg_type == NLMSG_ERROR)
|
/* May be multicast arriving async */
|
||||||
nl_err(h);
|
if (nl_async(h))
|
||||||
|
newaddr = 1;
|
||||||
|
}
|
||||||
else if (h->nlmsg_type == NLMSG_DONE)
|
else if (h->nlmsg_type == NLMSG_DONE)
|
||||||
return 1;
|
{
|
||||||
|
/* handle async new interface address arrivals, these have to be done
|
||||||
|
after we complete as we're not re-entrant */
|
||||||
|
if (newaddr)
|
||||||
|
{
|
||||||
|
time_t now = dnsmasq_time();
|
||||||
|
|
||||||
|
if (option_bool(OPT_CLEVERBIND))
|
||||||
|
{
|
||||||
|
enumerate_interfaces();
|
||||||
|
create_bound_listeners(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_dhcp6 || daemon->doing_ra)
|
||||||
|
dhcp_construct_contexts(now);
|
||||||
|
|
||||||
|
if (daemon->doing_dhcp6)
|
||||||
|
lease_find_interfaces(now);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return callback_ok;
|
||||||
|
}
|
||||||
else if (h->nlmsg_type == RTM_NEWADDR && family != AF_UNSPEC && family != AF_LOCAL)
|
else if (h->nlmsg_type == RTM_NEWADDR && family != AF_UNSPEC && family != AF_LOCAL)
|
||||||
{
|
{
|
||||||
struct ifaddrmsg *ifa = NLMSG_DATA(h);
|
struct ifaddrmsg *ifa = NLMSG_DATA(h);
|
||||||
@@ -213,26 +244,33 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
rta = RTA_NEXT(rta, len1);
|
rta = RTA_NEXT(rta, len1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addr.s_addr)
|
if (addr.s_addr && callback_ok)
|
||||||
if (!((*callback)(addr, ifa->ifa_index, netmask, broadcast, parm)))
|
if (!((*callback)(addr, ifa->ifa_index, netmask, broadcast, parm)))
|
||||||
return 0;
|
callback_ok = 0;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
else if (ifa->ifa_family == AF_INET6)
|
else if (ifa->ifa_family == AF_INET6)
|
||||||
{
|
{
|
||||||
struct in6_addr *addrp = NULL;
|
struct in6_addr *addrp = NULL;
|
||||||
|
u32 valid = 0, preferred = 0;
|
||||||
while (RTA_OK(rta, len1))
|
while (RTA_OK(rta, len1))
|
||||||
{
|
{
|
||||||
if (rta->rta_type == IFA_ADDRESS)
|
if (rta->rta_type == IFA_ADDRESS)
|
||||||
addrp = ((struct in6_addr *)(rta+1));
|
addrp = ((struct in6_addr *)(rta+1));
|
||||||
|
else if (rta->rta_type == IFA_CACHEINFO)
|
||||||
|
{
|
||||||
|
struct ifa_cacheinfo *ifc = (struct ifa_cacheinfo *)(rta+1);
|
||||||
|
preferred = ifc->ifa_prefered;
|
||||||
|
valid = ifc->ifa_valid;
|
||||||
|
}
|
||||||
rta = RTA_NEXT(rta, len1);
|
rta = RTA_NEXT(rta, len1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addrp)
|
if (addrp && callback_ok)
|
||||||
if (!((*callback)(addrp, ifa->ifa_prefixlen, ifa->ifa_index,
|
if (!((*callback)(addrp, (int)(ifa->ifa_prefixlen), (int)(ifa->ifa_scope),
|
||||||
ifa->ifa_index, ifa->ifa_flags & IFA_F_TENTATIVE, parm)))
|
(int)(ifa->ifa_index), (int)(ifa->ifa_flags & IFA_F_TENTATIVE),
|
||||||
return 0;
|
(int) preferred, (int)valid, parm)))
|
||||||
|
callback_ok = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -258,9 +296,9 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
rta = RTA_NEXT(rta, len1);
|
rta = RTA_NEXT(rta, len1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inaddr && mac)
|
if (inaddr && mac && callback_ok)
|
||||||
if (!((*callback)(neigh->ndm_family, inaddr, mac, maclen, parm)))
|
if (!((*callback)(neigh->ndm_family, inaddr, mac, maclen, parm)))
|
||||||
return 0;
|
callback_ok = 0;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
else if (h->nlmsg_type == RTM_NEWLINK && family == AF_LOCAL)
|
else if (h->nlmsg_type == RTM_NEWLINK && family == AF_LOCAL)
|
||||||
@@ -282,18 +320,19 @@ int iface_enumerate(int family, void *parm, int (*callback)())
|
|||||||
rta = RTA_NEXT(rta, len1);
|
rta = RTA_NEXT(rta, len1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mac && !((*callback)(link->ifi_type, link->ifi_flags, mac, maclen, parm)))
|
if (mac && callback_ok && !((link->ifi_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) &&
|
||||||
return 0;
|
!((*callback)((int)link->ifi_index, (unsigned int)link->ifi_type, mac, maclen, parm)))
|
||||||
|
callback_ok = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void netlink_multicast(void)
|
void netlink_multicast(time_t now)
|
||||||
{
|
{
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
struct nlmsghdr *h;
|
struct nlmsghdr *h;
|
||||||
int flags;
|
int flags, newaddr = 0;
|
||||||
|
|
||||||
/* don't risk blocking reading netlink messages here. */
|
/* don't risk blocking reading netlink messages here. */
|
||||||
if ((flags = fcntl(daemon->netlinkfd, F_GETFL)) == -1 ||
|
if ((flags = fcntl(daemon->netlinkfd, F_GETFL)) == -1 ||
|
||||||
@@ -301,59 +340,77 @@ void netlink_multicast(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if ((len = netlink_recv()) != -1)
|
if ((len = netlink_recv()) != -1)
|
||||||
{
|
for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
|
||||||
for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len))
|
if (nl_async(h))
|
||||||
if (h->nlmsg_type == NLMSG_ERROR)
|
newaddr = 1;
|
||||||
nl_err(h);
|
|
||||||
else
|
|
||||||
nl_routechange(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* restore non-blocking status */
|
|
||||||
fcntl(daemon->netlinkfd, F_SETFL, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nl_err(struct nlmsghdr *h)
|
|
||||||
{
|
|
||||||
struct nlmsgerr *err = NLMSG_DATA(h);
|
|
||||||
|
|
||||||
if (err->error != 0)
|
/* restore non-blocking status */
|
||||||
my_syslog(LOG_ERR, _("netlink returns error: %s"), strerror(-(err->error)));
|
fcntl(daemon->netlinkfd, F_SETFL, flags);
|
||||||
}
|
|
||||||
|
|
||||||
/* We arrange to receive netlink multicast messages whenever the network route is added.
|
if (newaddr)
|
||||||
If this happens and we still have a DNS packet in the buffer, we re-send it.
|
|
||||||
This helps on DoD links, where frequently the packet which triggers dialling is
|
|
||||||
a DNS query, which then gets lost. By re-sending, we can avoid the lookup
|
|
||||||
failing. Note that we only accept these messages from the kernel (pid == 0) */
|
|
||||||
static void nl_routechange(struct nlmsghdr *h)
|
|
||||||
{
|
|
||||||
if (h->nlmsg_pid == 0 && h->nlmsg_type == RTM_NEWROUTE)
|
|
||||||
{
|
{
|
||||||
struct rtmsg *rtm = NLMSG_DATA(h);
|
if (option_bool(OPT_CLEVERBIND))
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (rtm->rtm_type != RTN_UNICAST || rtm->rtm_scope != RT_SCOPE_LINK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Force re-reading resolv file right now, for luck. */
|
|
||||||
daemon->last_resolv = 0;
|
|
||||||
|
|
||||||
if (daemon->srv_save)
|
|
||||||
{
|
{
|
||||||
if (daemon->srv_save->sfd)
|
enumerate_interfaces();
|
||||||
fd = daemon->srv_save->sfd->fd;
|
create_bound_listeners(0);
|
||||||
else if (daemon->rfd_save && daemon->rfd_save->refcount != 0)
|
|
||||||
fd = daemon->rfd_save->fd;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
while(sendto(fd, daemon->packet, daemon->packet_len, 0,
|
|
||||||
&daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
if (daemon->doing_dhcp6 || daemon->doing_ra)
|
||||||
|
dhcp_construct_contexts(now);
|
||||||
|
|
||||||
|
if (daemon->doing_dhcp6)
|
||||||
|
lease_find_interfaces(now);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nl_async(struct nlmsghdr *h)
|
||||||
|
{
|
||||||
|
if (h->nlmsg_type == NLMSG_ERROR)
|
||||||
|
{
|
||||||
|
struct nlmsgerr *err = NLMSG_DATA(h);
|
||||||
|
if (err->error != 0)
|
||||||
|
my_syslog(LOG_ERR, _("netlink returns error: %s"), strerror(-(err->error)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (h->nlmsg_pid == 0 && h->nlmsg_type == RTM_NEWROUTE)
|
||||||
|
{
|
||||||
|
/* We arrange to receive netlink multicast messages whenever the network route is added.
|
||||||
|
If this happens and we still have a DNS packet in the buffer, we re-send it.
|
||||||
|
This helps on DoD links, where frequently the packet which triggers dialling is
|
||||||
|
a DNS query, which then gets lost. By re-sending, we can avoid the lookup
|
||||||
|
failing. */
|
||||||
|
struct rtmsg *rtm = NLMSG_DATA(h);
|
||||||
|
|
||||||
|
if (rtm->rtm_type == RTN_UNICAST && rtm->rtm_scope == RT_SCOPE_LINK)
|
||||||
|
{
|
||||||
|
/* Force re-reading resolv file right now, for luck. */
|
||||||
|
daemon->last_resolv = 0;
|
||||||
|
|
||||||
|
if (daemon->srv_save)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (daemon->srv_save->sfd)
|
||||||
|
fd = daemon->srv_save->sfd->fd;
|
||||||
|
else if (daemon->rfd_save && daemon->rfd_save->refcount != 0)
|
||||||
|
fd = daemon->rfd_save->fd;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
while(sendto(fd, daemon->packet, daemon->packet_len, 0,
|
||||||
|
&daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR)
|
||||||
|
return 1; /* clever bind mode - rescan */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
+132
-78
@@ -107,7 +107,7 @@ int indextoname(int fd, int index, char *name)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int iface_check(int family, struct all_addr *addr, char *name)
|
int iface_check(int family, struct all_addr *addr, char *name, int *auth)
|
||||||
{
|
{
|
||||||
struct iname *tmp;
|
struct iname *tmp;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
@@ -115,43 +115,59 @@ int iface_check(int family, struct all_addr *addr, char *name)
|
|||||||
/* Note: have to check all and not bail out early, so that we set the
|
/* Note: have to check all and not bail out early, so that we set the
|
||||||
"used" flags. */
|
"used" flags. */
|
||||||
|
|
||||||
|
if (auth)
|
||||||
|
*auth = 0;
|
||||||
|
|
||||||
if (daemon->if_names || daemon->if_addrs)
|
if (daemon->if_names || daemon->if_addrs)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DHCP
|
|
||||||
struct dhcp_context *range;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
|
||||||
for (range = daemon->dhcp; range; range = range->next)
|
|
||||||
if (range->interface && strcmp(range->interface, name) == 0)
|
|
||||||
ret = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (tmp = daemon->if_names; tmp; tmp = tmp->next)
|
for (tmp = daemon->if_names; tmp; tmp = tmp->next)
|
||||||
if (tmp->name && (strcmp(tmp->name, name) == 0))
|
if (tmp->name && (strcmp(tmp->name, name) == 0))
|
||||||
ret = tmp->used = 1;
|
ret = tmp->used = 1;
|
||||||
|
|
||||||
for (tmp = daemon->if_addrs; tmp; tmp = tmp->next)
|
if (addr)
|
||||||
if (tmp->addr.sa.sa_family == family)
|
for (tmp = daemon->if_addrs; tmp; tmp = tmp->next)
|
||||||
{
|
if (tmp->addr.sa.sa_family == family)
|
||||||
if (family == AF_INET &&
|
{
|
||||||
tmp->addr.in.sin_addr.s_addr == addr->addr.addr4.s_addr)
|
if (family == AF_INET &&
|
||||||
ret = tmp->used = 1;
|
tmp->addr.in.sin_addr.s_addr == addr->addr.addr4.s_addr)
|
||||||
|
ret = tmp->used = 1;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
else if (family == AF_INET6 &&
|
else if (family == AF_INET6 &&
|
||||||
IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr,
|
IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr,
|
||||||
&addr->addr.addr6))
|
&addr->addr.addr6))
|
||||||
ret = tmp->used = 1;
|
ret = tmp->used = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (tmp = daemon->if_except; tmp; tmp = tmp->next)
|
for (tmp = daemon->if_except; tmp; tmp = tmp->next)
|
||||||
if (tmp->name && (strcmp(tmp->name, name) == 0))
|
if (tmp->name && (strcmp(tmp->name, name) == 0))
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
|
||||||
|
for (tmp = daemon->authinterface; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->name)
|
||||||
|
{
|
||||||
|
if (strcmp(tmp->name, name) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (addr && tmp->addr.sa.sa_family == AF_INET && family == AF_INET &&
|
||||||
|
tmp->addr.in.sin_addr.s_addr == addr->addr.addr4.s_addr)
|
||||||
|
break;
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else if (addr && tmp->addr.sa.sa_family == AF_INET6 && family == AF_INET6 &&
|
||||||
|
IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr, &addr->addr.addr6))
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (tmp && auth)
|
||||||
|
{
|
||||||
|
*auth = 1;
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,11 +177,12 @@ static int iface_allowed(struct irec **irecp, int if_index,
|
|||||||
struct irec *iface;
|
struct irec *iface;
|
||||||
int fd, mtu = 0, loopback;
|
int fd, mtu = 0, loopback;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int tftp_ok = daemon->tftp_unlimited;
|
int tftp_ok = !!option_bool(OPT_TFTP);
|
||||||
|
int dhcp_ok = 1;
|
||||||
|
int auth_dns = 0;
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
struct iname *tmp;
|
struct iname *tmp;
|
||||||
#endif
|
#endif
|
||||||
struct interface_list *ir = NULL;
|
|
||||||
|
|
||||||
/* check whether the interface IP has been added already
|
/* check whether the interface IP has been added already
|
||||||
we call this routine multiple times. */
|
we call this routine multiple times. */
|
||||||
@@ -190,6 +207,9 @@ static int iface_allowed(struct irec **irecp, int if_index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
loopback = ifr.ifr_flags & IFF_LOOPBACK;
|
loopback = ifr.ifr_flags & IFF_LOOPBACK;
|
||||||
|
|
||||||
|
if (loopback)
|
||||||
|
dhcp_ok = 0;
|
||||||
|
|
||||||
if (ioctl(fd, SIOCGIFMTU, &ifr) != -1)
|
if (ioctl(fd, SIOCGIFMTU, &ifr) != -1)
|
||||||
mtu = ifr.ifr_mtu;
|
mtu = ifr.ifr_mtu;
|
||||||
@@ -203,65 +223,64 @@ static int iface_allowed(struct irec **irecp, int if_index,
|
|||||||
struct iname *lo;
|
struct iname *lo;
|
||||||
for (lo = daemon->if_names; lo; lo = lo->next)
|
for (lo = daemon->if_names; lo; lo = lo->next)
|
||||||
if (lo->name && strcmp(lo->name, ifr.ifr_name) == 0)
|
if (lo->name && strcmp(lo->name, ifr.ifr_name) == 0)
|
||||||
{
|
break;
|
||||||
lo->isloop = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lo &&
|
if (!lo &&
|
||||||
(lo = whine_malloc(sizeof(struct iname))) &&
|
(lo = whine_malloc(sizeof(struct iname))) &&
|
||||||
(lo->name = whine_malloc(strlen(ifr.ifr_name)+1)))
|
(lo->name = whine_malloc(strlen(ifr.ifr_name)+1)))
|
||||||
{
|
{
|
||||||
strcpy(lo->name, ifr.ifr_name);
|
strcpy(lo->name, ifr.ifr_name);
|
||||||
lo->isloop = lo->used = 1;
|
lo->used = 1;
|
||||||
lo->next = daemon->if_names;
|
lo->next = daemon->if_names;
|
||||||
daemon->if_names = lo;
|
daemon->if_names = lo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TFTP
|
if (addr->sa.sa_family == AF_INET &&
|
||||||
/* implement wierd TFTP service rules */
|
!iface_check(AF_INET, (struct all_addr *)&addr->in.sin_addr, ifr.ifr_name, &auth_dns))
|
||||||
for (ir = daemon->tftp_interfaces; ir; ir = ir->next)
|
return 1;
|
||||||
if (strcmp(ir->interface, ifr.ifr_name) == 0)
|
|
||||||
{
|
|
||||||
tftp_ok = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!ir)
|
|
||||||
{
|
|
||||||
if (addr->sa.sa_family == AF_INET &&
|
|
||||||
!iface_check(AF_INET, (struct all_addr *)&addr->in.sin_addr, ifr.ifr_name))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
|
||||||
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
|
||||||
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
|
||||||
tftp_ok = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_IPV6
|
|
||||||
if (addr->sa.sa_family == AF_INET6 &&
|
|
||||||
!iface_check(AF_INET6, (struct all_addr *)&addr->in6.sin6_addr, ifr.ifr_name))
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
if (addr->sa.sa_family == AF_INET6 &&
|
||||||
|
!iface_check(AF_INET6, (struct all_addr *)&addr->in6.sin6_addr, ifr.ifr_name, &auth_dns))
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP
|
||||||
|
/* No DHCP where we're doing auth DNS. */
|
||||||
|
if (auth_dns)
|
||||||
|
{
|
||||||
|
tftp_ok = 0;
|
||||||
|
dhcp_ok = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
|
||||||
|
{
|
||||||
|
tftp_ok = 0;
|
||||||
|
dhcp_ok = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* add to list */
|
/* add to list */
|
||||||
if ((iface = whine_malloc(sizeof(struct irec))))
|
if ((iface = whine_malloc(sizeof(struct irec))))
|
||||||
{
|
{
|
||||||
iface->addr = *addr;
|
iface->addr = *addr;
|
||||||
iface->netmask = netmask;
|
iface->netmask = netmask;
|
||||||
iface->tftp_ok = tftp_ok;
|
iface->tftp_ok = tftp_ok;
|
||||||
|
iface->dhcp_ok = dhcp_ok;
|
||||||
|
iface->dns_auth = auth_dns;
|
||||||
iface->mtu = mtu;
|
iface->mtu = mtu;
|
||||||
iface->dad = dad;
|
iface->dad = dad;
|
||||||
iface->done = 0;
|
iface->done = 0;
|
||||||
if ((iface->name = whine_malloc(strlen(ifr.ifr_name)+1)))
|
if ((iface->name = whine_malloc(strlen(ifr.ifr_name)+1)))
|
||||||
strcpy(iface->name, ifr.ifr_name);
|
{
|
||||||
iface->next = *irecp;
|
strcpy(iface->name, ifr.ifr_name);
|
||||||
*irecp = iface;
|
iface->next = *irecp;
|
||||||
return 1;
|
*irecp = iface;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
free(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
@@ -270,13 +289,17 @@ static int iface_allowed(struct irec **irecp, int if_index,
|
|||||||
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
static int iface_allowed_v6(struct in6_addr *local, int prefix,
|
static int iface_allowed_v6(struct in6_addr *local, int prefix,
|
||||||
int scope, int if_index, int dad, void *vparam)
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam)
|
||||||
{
|
{
|
||||||
union mysockaddr addr;
|
union mysockaddr addr;
|
||||||
struct in_addr netmask; /* dummy */
|
struct in_addr netmask; /* dummy */
|
||||||
|
|
||||||
(void)prefix; /* warning */
|
|
||||||
netmask.s_addr = 0;
|
netmask.s_addr = 0;
|
||||||
|
|
||||||
|
(void)prefix; /* warning */
|
||||||
|
(void)scope; /* warning */
|
||||||
|
(void)preferred;
|
||||||
|
(void)valid;
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
@@ -285,7 +308,7 @@ static int iface_allowed_v6(struct in6_addr *local, int prefix,
|
|||||||
addr.in6.sin6_family = AF_INET6;
|
addr.in6.sin6_family = AF_INET6;
|
||||||
addr.in6.sin6_addr = *local;
|
addr.in6.sin6_addr = *local;
|
||||||
addr.in6.sin6_port = htons(daemon->port);
|
addr.in6.sin6_port = htons(daemon->port);
|
||||||
addr.in6.sin6_scope_id = scope;
|
addr.in6.sin6_scope_id = if_index;
|
||||||
|
|
||||||
return iface_allowed((struct irec **)vparam, if_index, &addr, netmask, dad);
|
return iface_allowed((struct irec **)vparam, if_index, &addr, netmask, dad);
|
||||||
}
|
}
|
||||||
@@ -338,6 +361,7 @@ static int make_sock(union mysockaddr *addr, int type, int dienow)
|
|||||||
if ((fd = socket(family, type, 0)) == -1)
|
if ((fd = socket(family, type, 0)) == -1)
|
||||||
{
|
{
|
||||||
int port;
|
int port;
|
||||||
|
char *s;
|
||||||
|
|
||||||
/* No error if the kernel just doesn't support this IP flavour */
|
/* No error if the kernel just doesn't support this IP flavour */
|
||||||
if (errno == EPROTONOSUPPORT ||
|
if (errno == EPROTONOSUPPORT ||
|
||||||
@@ -346,18 +370,27 @@ static int make_sock(union mysockaddr *addr, int type, int dienow)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
port = prettyprint_addr(addr, daemon->addrbuff);
|
||||||
|
if (!option_bool(OPT_NOWILD) && !option_bool(OPT_CLEVERBIND))
|
||||||
|
sprintf(daemon->addrbuff, "port %d", port);
|
||||||
|
s = _("failed to create listening socket for %s: %s");
|
||||||
|
|
||||||
|
if (fd != -1)
|
||||||
|
close (fd);
|
||||||
|
|
||||||
if (dienow)
|
if (dienow)
|
||||||
{
|
{
|
||||||
port = prettyprint_addr(addr, daemon->namebuff);
|
/* failure to bind addresses given by --listen-address at this point
|
||||||
if (!option_bool(OPT_NOWILD))
|
is OK if we're doing bind-dynamic */
|
||||||
sprintf(daemon->namebuff, "port %d", port);
|
if (!option_bool(OPT_CLEVERBIND))
|
||||||
die(_("failed to create listening socket for %s: %s"),
|
die(s, daemon->addrbuff, EC_BADNET);
|
||||||
daemon->namebuff, EC_BADNET);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
my_syslog(LOG_WARNING, s, daemon->addrbuff, strerror(errno));
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 || !fix_fd(fd))
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 || !fix_fd(fd))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@@ -475,8 +508,7 @@ static struct listener *create_listeners(union mysockaddr *addr, int do_tftp, in
|
|||||||
void create_wildcard_listeners(void)
|
void create_wildcard_listeners(void)
|
||||||
{
|
{
|
||||||
union mysockaddr addr;
|
union mysockaddr addr;
|
||||||
struct listener *l;
|
struct listener *l, *l6;
|
||||||
int tftp_enabled = daemon->tftp_unlimited || daemon->tftp_interfaces;
|
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
#ifdef HAVE_SOCKADDR_SA_LEN
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
@@ -486,7 +518,7 @@ void create_wildcard_listeners(void)
|
|||||||
addr.in.sin_addr.s_addr = INADDR_ANY;
|
addr.in.sin_addr.s_addr = INADDR_ANY;
|
||||||
addr.in.sin_port = htons(daemon->port);
|
addr.in.sin_port = htons(daemon->port);
|
||||||
|
|
||||||
l = create_listeners(&addr, tftp_enabled, 1);
|
l = create_listeners(&addr, !!option_bool(OPT_TFTP), 1);
|
||||||
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
@@ -496,11 +528,12 @@ void create_wildcard_listeners(void)
|
|||||||
addr.in6.sin6_family = AF_INET6;
|
addr.in6.sin6_family = AF_INET6;
|
||||||
addr.in6.sin6_addr = in6addr_any;
|
addr.in6.sin6_addr = in6addr_any;
|
||||||
addr.in6.sin6_port = htons(daemon->port);
|
addr.in6.sin6_port = htons(daemon->port);
|
||||||
|
|
||||||
|
l6 = create_listeners(&addr, !!option_bool(OPT_TFTP), 1);
|
||||||
if (l)
|
if (l)
|
||||||
l->next = create_listeners(&addr, tftp_enabled, 1);
|
l->next = l6;
|
||||||
else
|
else
|
||||||
l = create_listeners(&addr, tftp_enabled, 1);
|
l = l6;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
daemon->listeners = l;
|
daemon->listeners = l;
|
||||||
@@ -510,6 +543,7 @@ void create_bound_listeners(int dienow)
|
|||||||
{
|
{
|
||||||
struct listener *new;
|
struct listener *new;
|
||||||
struct irec *iface;
|
struct irec *iface;
|
||||||
|
struct iname *if_tmp;
|
||||||
|
|
||||||
for (iface = daemon->interfaces; iface; iface = iface->next)
|
for (iface = daemon->interfaces; iface; iface = iface->next)
|
||||||
if (!iface->done && !iface->dad &&
|
if (!iface->done && !iface->dad &&
|
||||||
@@ -520,6 +554,26 @@ void create_bound_listeners(int dienow)
|
|||||||
daemon->listeners = new;
|
daemon->listeners = new;
|
||||||
iface->done = 1;
|
iface->done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for --listen-address options that haven't been used because there's
|
||||||
|
no interface with a matching address. These may be valid: eg it's possible
|
||||||
|
to listen on 127.0.1.1 even if the loopback interface is 127.0.0.1
|
||||||
|
|
||||||
|
If the address isn't valid the bind() will fail and we'll die()
|
||||||
|
(except in bind-dynamic mode, when we'll complain but keep trying.)
|
||||||
|
|
||||||
|
The resulting listeners have the ->iface field NULL, and this has to be
|
||||||
|
handled by the DNS and TFTP code. It disables --localise-queries processing
|
||||||
|
(no netmask) and some MTU login the tftp code. */
|
||||||
|
|
||||||
|
for (if_tmp = daemon->if_addrs; if_tmp; if_tmp = if_tmp->next)
|
||||||
|
if (!if_tmp->used &&
|
||||||
|
(new = create_listeners(&if_tmp->addr, !!option_bool(OPT_TFTP), dienow)))
|
||||||
|
{
|
||||||
|
new->iface = NULL;
|
||||||
|
new->next = daemon->listeners;
|
||||||
|
daemon->listeners = new;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_dad_listeners(void)
|
int is_dad_listeners(void)
|
||||||
|
|||||||
+1071
-546
File diff suppressed because it is too large.
Load diff
+108
@@ -0,0 +1,108 @@
|
|||||||
|
/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 dated June, 1991, or
|
||||||
|
(at your option) version 3 dated 29 June, 2007.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
|
||||||
|
static size_t outpacket_counter;
|
||||||
|
|
||||||
|
void end_opt6(int container)
|
||||||
|
{
|
||||||
|
void *p = daemon->outpacket.iov_base + container + 2;
|
||||||
|
u16 len = outpacket_counter - container - 4 ;
|
||||||
|
|
||||||
|
PUTSHORT(len, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_counter(int newval)
|
||||||
|
{
|
||||||
|
int ret = outpacket_counter;
|
||||||
|
if (newval != -1)
|
||||||
|
outpacket_counter = newval;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *expand(size_t headroom)
|
||||||
|
{
|
||||||
|
void *ret;
|
||||||
|
|
||||||
|
if (expand_buf(&daemon->outpacket, outpacket_counter + headroom))
|
||||||
|
{
|
||||||
|
ret = daemon->outpacket.iov_base + outpacket_counter;
|
||||||
|
outpacket_counter += headroom;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int new_opt6(int opt)
|
||||||
|
{
|
||||||
|
int ret = outpacket_counter;
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
if ((p = expand(4)))
|
||||||
|
{
|
||||||
|
PUTSHORT(opt, p);
|
||||||
|
PUTSHORT(0, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *put_opt6(void *data, size_t len)
|
||||||
|
{
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
if ((p = expand(len)))
|
||||||
|
memcpy(p, data, len);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_opt6_long(unsigned int val)
|
||||||
|
{
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
if ((p = expand(4)))
|
||||||
|
PUTLONG(val, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_opt6_short(unsigned int val)
|
||||||
|
{
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
if ((p = expand(2)))
|
||||||
|
PUTSHORT(val, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_opt6_char(unsigned int val)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
if ((p = expand(1)))
|
||||||
|
*p = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_opt6_string(char *s)
|
||||||
|
{
|
||||||
|
put_opt6(s, strlen(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 dated June, 1991, or
|
||||||
|
(at your option) version 3 dated 29 June, 2007.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ALL_NODES "FF02::1"
|
||||||
|
#define ALL_ROUTERS "FF02::2"
|
||||||
|
|
||||||
|
struct ping_packet {
|
||||||
|
u8 type, code;
|
||||||
|
u16 checksum;
|
||||||
|
u16 identifier;
|
||||||
|
u16 sequence_no;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ra_packet {
|
||||||
|
u8 type, code;
|
||||||
|
u16 checksum;
|
||||||
|
u8 hop_limit, flags;
|
||||||
|
u16 lifetime;
|
||||||
|
u32 reachable_time;
|
||||||
|
u32 retrans_time;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct prefix_opt {
|
||||||
|
u8 type, len, prefix_len, flags;
|
||||||
|
u32 valid_lifetime, preferred_lifetime, reserved;
|
||||||
|
struct in6_addr prefix;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ICMP6_OPT_SOURCE_MAC 1
|
||||||
|
#define ICMP6_OPT_PREFIX 3
|
||||||
|
#define ICMP6_OPT_MTU 5
|
||||||
|
#define ICMP6_OPT_RDNSS 25
|
||||||
|
#define ICMP6_OPT_DNSSL 31
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+577
@@ -0,0 +1,577 @@
|
|||||||
|
/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 dated June, 1991, or
|
||||||
|
(at your option) version 3 dated 29 June, 2007.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* NB. This code may be called during a DHCPv4 or transaction which is in ping-wait
|
||||||
|
It therefore cannot use any DHCP buffer resources except outpacket, which is
|
||||||
|
not used by DHCPv4 code. This code may also be called when DHCP 4 or 6 isn't
|
||||||
|
active, so we ensure that outpacket is allocated here too */
|
||||||
|
|
||||||
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
|
||||||
|
#include <netinet/icmp6.h>
|
||||||
|
|
||||||
|
struct ra_param {
|
||||||
|
time_t now;
|
||||||
|
int ind, managed, other, found_context, first;
|
||||||
|
char *if_name;
|
||||||
|
struct dhcp_netid *tags;
|
||||||
|
struct in6_addr link_local;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct search_param {
|
||||||
|
time_t now; int iface;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void send_ra(time_t now, int iface, char *iface_name, struct in6_addr *dest);
|
||||||
|
static int add_prefixes(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam);
|
||||||
|
static int iface_search(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int prefered, int valid, void *vparam);
|
||||||
|
static int add_lla(int index, unsigned int type, char *mac, size_t maclen, void *parm);
|
||||||
|
|
||||||
|
static int hop_limit;
|
||||||
|
|
||||||
|
void ra_init(time_t now)
|
||||||
|
{
|
||||||
|
struct icmp6_filter filter;
|
||||||
|
int fd;
|
||||||
|
#if defined(IPV6_TCLASS) && defined(IPTOS_CLASS_CS6)
|
||||||
|
int class = IPTOS_CLASS_CS6;
|
||||||
|
#endif
|
||||||
|
int val = 255; /* radvd uses this value */
|
||||||
|
socklen_t len = sizeof(int);
|
||||||
|
struct dhcp_context *context;
|
||||||
|
|
||||||
|
/* ensure this is around even if we're not doing DHCPv6 */
|
||||||
|
expand_buf(&daemon->outpacket, sizeof(struct dhcp_packet));
|
||||||
|
|
||||||
|
/* See if we're guessing SLAAC addresses, if so we need to recieve ping replies */
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if ((context->flags & CONTEXT_RA_NAME))
|
||||||
|
break;
|
||||||
|
|
||||||
|
ICMP6_FILTER_SETBLOCKALL(&filter);
|
||||||
|
ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);
|
||||||
|
if (context)
|
||||||
|
ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filter);
|
||||||
|
|
||||||
|
if ((fd = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) == -1 ||
|
||||||
|
getsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hop_limit, &len) ||
|
||||||
|
#if defined(IPV6_TCLASS) && defined(IPTOS_CLASS_CS6)
|
||||||
|
setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &class, sizeof(class)) == -1 ||
|
||||||
|
#endif
|
||||||
|
!fix_fd(fd) ||
|
||||||
|
!set_ipv6pktinfo(fd) ||
|
||||||
|
setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val)) ||
|
||||||
|
setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)) ||
|
||||||
|
setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter)) == -1)
|
||||||
|
die (_("cannot create ICMPv6 socket: %s"), NULL, EC_BADNET);
|
||||||
|
|
||||||
|
daemon->icmp6fd = fd;
|
||||||
|
|
||||||
|
ra_start_unsolicted(now, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ra_start_unsolicted(time_t now, struct dhcp_context *context)
|
||||||
|
{
|
||||||
|
/* init timers so that we do ra's for some/all soon. some ra_times will end up zeroed
|
||||||
|
if it's not appropriate to advertise those contexts.
|
||||||
|
This gets re-called on a netlink route-change to re-do the advertisement
|
||||||
|
and pick up new interfaces */
|
||||||
|
|
||||||
|
if (context)
|
||||||
|
context->ra_short_period_start = context->ra_time = now;
|
||||||
|
else
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if (!(context->flags & CONTEXT_TEMPLATE))
|
||||||
|
{
|
||||||
|
context->ra_time = now + (rand16()/13000); /* range 0 - 5 */
|
||||||
|
/* re-do frequently for a minute or so, in case the first gets lost. */
|
||||||
|
context->ra_short_period_start = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void icmp6_packet(time_t now)
|
||||||
|
{
|
||||||
|
char interface[IF_NAMESIZE+1];
|
||||||
|
ssize_t sz;
|
||||||
|
int if_index = 0;
|
||||||
|
struct cmsghdr *cmptr;
|
||||||
|
struct msghdr msg;
|
||||||
|
union {
|
||||||
|
struct cmsghdr align; /* this ensures alignment */
|
||||||
|
char control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
||||||
|
} control_u;
|
||||||
|
struct sockaddr_in6 from;
|
||||||
|
unsigned char *packet;
|
||||||
|
struct iname *tmp;
|
||||||
|
|
||||||
|
/* Note: use outpacket for input buffer */
|
||||||
|
msg.msg_control = control_u.control6;
|
||||||
|
msg.msg_controllen = sizeof(control_u);
|
||||||
|
msg.msg_flags = 0;
|
||||||
|
msg.msg_name = &from;
|
||||||
|
msg.msg_namelen = sizeof(from);
|
||||||
|
msg.msg_iov = &daemon->outpacket;
|
||||||
|
msg.msg_iovlen = 1;
|
||||||
|
|
||||||
|
if ((sz = recv_dhcp_packet(daemon->icmp6fd, &msg)) == -1 || sz < 8)
|
||||||
|
return;
|
||||||
|
|
||||||
|
packet = (unsigned char *)daemon->outpacket.iov_base;
|
||||||
|
|
||||||
|
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
|
||||||
|
if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo)
|
||||||
|
{
|
||||||
|
union {
|
||||||
|
unsigned char *c;
|
||||||
|
struct in6_pktinfo *p;
|
||||||
|
} p;
|
||||||
|
p.c = CMSG_DATA(cmptr);
|
||||||
|
|
||||||
|
if_index = p.p->ipi6_ifindex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!indextoname(daemon->icmp6fd, if_index, interface))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!iface_check(AF_LOCAL, NULL, interface, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->name && (strcmp(tmp->name, interface) == 0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (packet[1] != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (packet[0] == ICMP6_ECHO_REPLY)
|
||||||
|
lease_ping_reply(&from.sin6_addr, packet, interface);
|
||||||
|
else if (packet[0] == ND_ROUTER_SOLICIT)
|
||||||
|
{
|
||||||
|
char *mac = "";
|
||||||
|
|
||||||
|
/* look for link-layer address option for logging */
|
||||||
|
if (sz >= 16 && packet[8] == ICMP6_OPT_SOURCE_MAC && (packet[9] * 8) + 8 <= sz)
|
||||||
|
{
|
||||||
|
print_mac(daemon->namebuff, &packet[10], (packet[9] * 8) - 2);
|
||||||
|
mac = daemon->namebuff;
|
||||||
|
}
|
||||||
|
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, "RTR-SOLICIT(%s) %s", interface, mac);
|
||||||
|
/* source address may not be valid in solicit request. */
|
||||||
|
send_ra(now, if_index, interface, !IN6_IS_ADDR_UNSPECIFIED(&from.sin6_addr) ? &from.sin6_addr : NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void send_ra(time_t now, int iface, char *iface_name, struct in6_addr *dest)
|
||||||
|
{
|
||||||
|
struct ra_packet *ra;
|
||||||
|
struct ra_param parm;
|
||||||
|
struct ifreq ifr;
|
||||||
|
struct sockaddr_in6 addr;
|
||||||
|
struct dhcp_context *context;
|
||||||
|
struct dhcp_netid iface_id;
|
||||||
|
struct dhcp_opt *opt_cfg;
|
||||||
|
int done_dns = 0;
|
||||||
|
|
||||||
|
save_counter(0);
|
||||||
|
ra = expand(sizeof(struct ra_packet));
|
||||||
|
|
||||||
|
ra->type = ND_ROUTER_ADVERT;
|
||||||
|
ra->code = 0;
|
||||||
|
ra->hop_limit = hop_limit;
|
||||||
|
ra->flags = 0x00;
|
||||||
|
ra->lifetime = htons(1800); /* AdvDefaultLifetime*/
|
||||||
|
ra->reachable_time = 0;
|
||||||
|
ra->retrans_time = 0;
|
||||||
|
|
||||||
|
parm.ind = iface;
|
||||||
|
parm.managed = 0;
|
||||||
|
parm.other = 0;
|
||||||
|
parm.found_context = 0;
|
||||||
|
parm.if_name = iface_name;
|
||||||
|
parm.first = 1;
|
||||||
|
parm.now = now;
|
||||||
|
|
||||||
|
/* set tag with name == interface */
|
||||||
|
iface_id.net = iface_name;
|
||||||
|
iface_id.next = NULL;
|
||||||
|
parm.tags = &iface_id;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
{
|
||||||
|
context->flags &= ~CONTEXT_RA_DONE;
|
||||||
|
context->netid.next = &context->netid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!iface_enumerate(AF_INET6, &parm, add_prefixes) ||
|
||||||
|
!parm.found_context)
|
||||||
|
return;
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, iface_name, IF_NAMESIZE);
|
||||||
|
|
||||||
|
if (ioctl(daemon->icmp6fd, SIOCGIFMTU, &ifr) != -1)
|
||||||
|
{
|
||||||
|
put_opt6_char(ICMP6_OPT_MTU);
|
||||||
|
put_opt6_char(1);
|
||||||
|
put_opt6_short(0);
|
||||||
|
put_opt6_long(ifr.ifr_mtu);
|
||||||
|
}
|
||||||
|
|
||||||
|
iface_enumerate(AF_LOCAL, &iface, add_lla);
|
||||||
|
|
||||||
|
/* RDNSS, RFC 6106, use relevant DHCP6 options */
|
||||||
|
(void)option_filter(parm.tags, NULL, daemon->dhcp_opts6);
|
||||||
|
|
||||||
|
for (opt_cfg = daemon->dhcp_opts6; opt_cfg; opt_cfg = opt_cfg->next)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* netids match and not encapsulated? */
|
||||||
|
if (!(opt_cfg->flags & DHOPT_TAGOK))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (opt_cfg->opt == OPTION6_DNS_SERVER)
|
||||||
|
{
|
||||||
|
struct in6_addr *a = (struct in6_addr *)opt_cfg->val;
|
||||||
|
|
||||||
|
done_dns = 1;
|
||||||
|
if (opt_cfg->len == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
put_opt6_char(ICMP6_OPT_RDNSS);
|
||||||
|
put_opt6_char((opt_cfg->len/8) + 1);
|
||||||
|
put_opt6_short(0);
|
||||||
|
put_opt6_long(1800); /* lifetime - twice RA retransmit */
|
||||||
|
/* zero means "self" */
|
||||||
|
for (i = 0; i < opt_cfg->len; i += IN6ADDRSZ, a++)
|
||||||
|
if (IN6_IS_ADDR_UNSPECIFIED(a))
|
||||||
|
put_opt6(&parm.link_local, IN6ADDRSZ);
|
||||||
|
else
|
||||||
|
put_opt6(a, IN6ADDRSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt_cfg->opt == OPTION6_DOMAIN_SEARCH && opt_cfg->len != 0)
|
||||||
|
{
|
||||||
|
int len = ((opt_cfg->len+7)/8);
|
||||||
|
|
||||||
|
put_opt6_char(ICMP6_OPT_DNSSL);
|
||||||
|
put_opt6_char(len + 1);
|
||||||
|
put_opt6_short(0);
|
||||||
|
put_opt6_long(1800); /* lifetime - twice RA retransmit */
|
||||||
|
put_opt6(opt_cfg->val, opt_cfg->len);
|
||||||
|
|
||||||
|
/* pad */
|
||||||
|
for (i = opt_cfg->len; i < len * 8; i++)
|
||||||
|
put_opt6_char(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!done_dns)
|
||||||
|
{
|
||||||
|
/* default == us. */
|
||||||
|
put_opt6_char(ICMP6_OPT_RDNSS);
|
||||||
|
put_opt6_char(3);
|
||||||
|
put_opt6_short(0);
|
||||||
|
put_opt6_long(1800); /* lifetime - twice RA retransmit */
|
||||||
|
put_opt6(&parm.link_local, IN6ADDRSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set managed bits unless we're providing only RA on this link */
|
||||||
|
if (parm.managed)
|
||||||
|
ra->flags |= 0x80; /* M flag, managed, */
|
||||||
|
if (parm.other)
|
||||||
|
ra->flags |= 0x40; /* O flag, other */
|
||||||
|
|
||||||
|
/* decide where we're sending */
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
|
addr.sin6_len = sizeof(struct sockaddr_in6);
|
||||||
|
#endif
|
||||||
|
addr.sin6_family = AF_INET6;
|
||||||
|
addr.sin6_port = htons(IPPROTO_ICMPV6);
|
||||||
|
if (dest)
|
||||||
|
{
|
||||||
|
addr.sin6_addr = *dest;
|
||||||
|
if (IN6_IS_ADDR_LINKLOCAL(dest) ||
|
||||||
|
IN6_IS_ADDR_MC_LINKLOCAL(dest))
|
||||||
|
addr.sin6_scope_id = iface;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
inet_pton(AF_INET6, ALL_NODES, &addr.sin6_addr);
|
||||||
|
|
||||||
|
send_from(daemon->icmp6fd, 0, daemon->outpacket.iov_base, save_counter(0),
|
||||||
|
(union mysockaddr *)&addr, (struct all_addr *)&parm.link_local, iface);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int add_prefixes(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam)
|
||||||
|
{
|
||||||
|
struct ra_param *param = vparam;
|
||||||
|
|
||||||
|
(void)scope; /* warning */
|
||||||
|
(void)dad;
|
||||||
|
(void)preferred;
|
||||||
|
(void)valid;
|
||||||
|
|
||||||
|
if (if_index == param->ind)
|
||||||
|
{
|
||||||
|
if (IN6_IS_ADDR_LINKLOCAL(local))
|
||||||
|
param->link_local = *local;
|
||||||
|
else if (!IN6_IS_ADDR_LOOPBACK(local) &&
|
||||||
|
!IN6_IS_ADDR_MULTICAST(local))
|
||||||
|
{
|
||||||
|
int do_prefix = 0;
|
||||||
|
int do_slaac = 0;
|
||||||
|
int deprecate = 0;
|
||||||
|
int found_constructed = 0;
|
||||||
|
unsigned int time = 0xffffffff;
|
||||||
|
int calc_valid = 0, calc_preferred = 0;
|
||||||
|
struct dhcp_context *context;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if (!(context->flags & CONTEXT_TEMPLATE) &&
|
||||||
|
prefix == context->prefix &&
|
||||||
|
is_same_net6(local, &context->start6, prefix) &&
|
||||||
|
is_same_net6(local, &context->end6, prefix))
|
||||||
|
{
|
||||||
|
if ((context->flags &
|
||||||
|
(CONTEXT_RA_ONLY | CONTEXT_RA_NAME | CONTEXT_RA_STATELESS)))
|
||||||
|
{
|
||||||
|
do_slaac = 1;
|
||||||
|
if (context->flags & CONTEXT_DHCP)
|
||||||
|
{
|
||||||
|
param->other = 1;
|
||||||
|
if (!(context->flags & CONTEXT_RA_STATELESS))
|
||||||
|
param->managed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* don't do RA for non-ra-only unless --enable-ra is set */
|
||||||
|
if (!option_bool(OPT_RA))
|
||||||
|
continue;
|
||||||
|
param->managed = 1;
|
||||||
|
param->other = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->flags & CONTEXT_CONSTRUCTED)
|
||||||
|
{
|
||||||
|
found_constructed = 1;
|
||||||
|
calc_valid = context->valid;
|
||||||
|
calc_preferred = context->preferred;
|
||||||
|
if (context->valid != -1)
|
||||||
|
calc_valid -= (int)param->now;
|
||||||
|
if (context->preferred != -1)
|
||||||
|
calc_preferred -= (int)param->now;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* find floor time */
|
||||||
|
if (time > context->lease_time)
|
||||||
|
time = context->lease_time;
|
||||||
|
|
||||||
|
if (context->flags & CONTEXT_DEPRECATE)
|
||||||
|
deprecate = 1;
|
||||||
|
|
||||||
|
/* collect dhcp-range tags */
|
||||||
|
if (context->netid.next == &context->netid && context->netid.net)
|
||||||
|
{
|
||||||
|
context->netid.next = param->tags;
|
||||||
|
param->tags = &context->netid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* subsequent prefixes on the same interface
|
||||||
|
and subsequent instances of this prefix don't need timers.
|
||||||
|
Be careful not to find the same prefix twice with different
|
||||||
|
addresses. */
|
||||||
|
if (!(context->flags & CONTEXT_RA_DONE))
|
||||||
|
{
|
||||||
|
if (!param->first)
|
||||||
|
context->ra_time = 0;
|
||||||
|
context->flags |= CONTEXT_RA_DONE;
|
||||||
|
do_prefix = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
param->first = 0;
|
||||||
|
param->found_context = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found_constructed)
|
||||||
|
{
|
||||||
|
calc_valid = time;
|
||||||
|
calc_preferred = deprecate ? 0 : time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_prefix)
|
||||||
|
{
|
||||||
|
struct prefix_opt *opt;
|
||||||
|
|
||||||
|
if ((opt = expand(sizeof(struct prefix_opt))))
|
||||||
|
{
|
||||||
|
/* zero net part of address */
|
||||||
|
setaddr6part(local, addr6part(local) & ~((prefix == 64) ? (u64)-1LL : (1LLU << (128 - prefix)) - 1LLU));
|
||||||
|
|
||||||
|
/* lifetimes must be min 2 hrs, by RFC 2462 */
|
||||||
|
if (time < 7200)
|
||||||
|
time = 7200;
|
||||||
|
|
||||||
|
opt->type = ICMP6_OPT_PREFIX;
|
||||||
|
opt->len = 4;
|
||||||
|
opt->prefix_len = prefix;
|
||||||
|
/* autonomous only if we're not doing dhcp, always set "on-link" */
|
||||||
|
opt->flags = do_slaac ? 0xC0 : 0x80;
|
||||||
|
opt->valid_lifetime = htonl(calc_valid);
|
||||||
|
opt->preferred_lifetime = htonl(calc_preferred);
|
||||||
|
opt->reserved = 0;
|
||||||
|
opt->prefix = *local;
|
||||||
|
|
||||||
|
inet_ntop(AF_INET6, local, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s", param->if_name, daemon->addrbuff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int add_lla(int index, unsigned int type, char *mac, size_t maclen, void *parm)
|
||||||
|
{
|
||||||
|
(void)type;
|
||||||
|
|
||||||
|
if (index == *((int *)parm))
|
||||||
|
{
|
||||||
|
/* size is in units of 8 octets and includes type and length (2 bytes)
|
||||||
|
add 7 to round up */
|
||||||
|
int len = (maclen + 9) >> 3;
|
||||||
|
unsigned char *p = expand(len << 3);
|
||||||
|
memset(p, 0, len << 3);
|
||||||
|
*p++ = ICMP6_OPT_SOURCE_MAC;
|
||||||
|
*p++ = len;
|
||||||
|
memcpy(p, mac, maclen);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t periodic_ra(time_t now)
|
||||||
|
{
|
||||||
|
struct search_param param;
|
||||||
|
struct dhcp_context *context;
|
||||||
|
time_t next_event;
|
||||||
|
char interface[IF_NAMESIZE+1];
|
||||||
|
|
||||||
|
param.now = now;
|
||||||
|
param.iface = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* find overdue events, and time of first future event */
|
||||||
|
for (next_event = 0, context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if (context->ra_time != 0)
|
||||||
|
{
|
||||||
|
if (difftime(context->ra_time, now) <= 0.0)
|
||||||
|
break; /* overdue */
|
||||||
|
|
||||||
|
if (next_event == 0 || difftime(next_event, context->ra_time) > 0.0)
|
||||||
|
next_event = context->ra_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* none overdue */
|
||||||
|
if (!context)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* There's a context overdue, but we can't find an interface
|
||||||
|
associated with it, because it's for a subnet we dont
|
||||||
|
have an interface on. Probably we're doing DHCP on
|
||||||
|
a remote subnet via a relay. Zero the timer, since we won't
|
||||||
|
ever be able to send ra's and satistfy it. */
|
||||||
|
if (iface_enumerate(AF_INET6, ¶m, iface_search))
|
||||||
|
context->ra_time = 0;
|
||||||
|
else if (param.iface != 0 &&
|
||||||
|
indextoname(daemon->icmp6fd, param.iface, interface) &&
|
||||||
|
iface_check(AF_LOCAL, NULL, interface, NULL))
|
||||||
|
{
|
||||||
|
struct iname *tmp;
|
||||||
|
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
||||||
|
if (tmp->name && (strcmp(tmp->name, interface) == 0))
|
||||||
|
break;
|
||||||
|
if (!tmp)
|
||||||
|
send_ra(now, param.iface, interface, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int iface_search(struct in6_addr *local, int prefix,
|
||||||
|
int scope, int if_index, int dad,
|
||||||
|
int preferred, int valid, void *vparam)
|
||||||
|
{
|
||||||
|
struct search_param *param = vparam;
|
||||||
|
struct dhcp_context *context;
|
||||||
|
|
||||||
|
(void)scope;
|
||||||
|
(void)dad;
|
||||||
|
(void)preferred;
|
||||||
|
(void)valid;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if (!(context->flags & CONTEXT_TEMPLATE) &&
|
||||||
|
prefix == context->prefix &&
|
||||||
|
is_same_net6(local, &context->start6, prefix) &&
|
||||||
|
is_same_net6(local, &context->end6, prefix) &&
|
||||||
|
context->ra_time != 0 &&
|
||||||
|
difftime(context->ra_time, param->now) <= 0.0)
|
||||||
|
{
|
||||||
|
/* found an interface that's overdue for RA determine new
|
||||||
|
timeout value and arrange for RA to be sent unless interface is
|
||||||
|
still doing DAD.*/
|
||||||
|
|
||||||
|
if (!dad)
|
||||||
|
param->iface = if_index;
|
||||||
|
|
||||||
|
if (difftime(param->now, context->ra_short_period_start) < 60.0)
|
||||||
|
/* range 5 - 20 */
|
||||||
|
context->ra_time = param->now + 5 + (rand16()/4400);
|
||||||
|
else
|
||||||
|
/* range 450 - 600 */
|
||||||
|
context->ra_time = param->now + 450 + (rand16()/440);
|
||||||
|
|
||||||
|
/* zero timers for other contexts on the same subnet, so they don't timeout
|
||||||
|
independently */
|
||||||
|
for (context = context->next; context; context = context->next)
|
||||||
|
if (prefix == context->prefix &&
|
||||||
|
is_same_net6(local, &context->start6, prefix) &&
|
||||||
|
is_same_net6(local, &context->end6, prefix))
|
||||||
|
context->ra_time = 0;
|
||||||
|
|
||||||
|
return 0; /* found, abort */
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1; /* keep searching */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+89
-35
@@ -16,19 +16,15 @@
|
|||||||
|
|
||||||
#include "dnsmasq.h"
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
static int add_resource_record(struct dns_header *header, char *limit, int *truncp,
|
|
||||||
unsigned int nameoffset, unsigned char **pp,
|
|
||||||
unsigned long ttl, unsigned int *offset, unsigned short type,
|
|
||||||
unsigned short class, char *format, ...);
|
|
||||||
|
|
||||||
#define CHECK_LEN(header, pp, plen, len) \
|
#define CHECK_LEN(header, pp, plen, len) \
|
||||||
((size_t)((pp) - (unsigned char *)(header) + (len)) <= (plen))
|
((size_t)((pp) - (unsigned char *)(header) + (len)) <= (plen))
|
||||||
|
|
||||||
#define ADD_RDLEN(header, pp, plen, len) \
|
#define ADD_RDLEN(header, pp, plen, len) \
|
||||||
(!CHECK_LEN(header, pp, plen, len) ? 0 : (long)((pp) += (len)), 1)
|
(!CHECK_LEN(header, pp, plen, len) ? 0 : (((pp) += (len)), 1))
|
||||||
|
|
||||||
static int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
|
int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
|
||||||
char *name, int isExtract, int extrabytes)
|
char *name, int isExtract, int extrabytes)
|
||||||
{
|
{
|
||||||
unsigned char *cp = (unsigned char *)name, *p = *pp, *p1 = NULL;
|
unsigned char *cp = (unsigned char *)name, *p = *pp, *p1 = NULL;
|
||||||
unsigned int j, l, hops = 0;
|
unsigned int j, l, hops = 0;
|
||||||
@@ -173,7 +169,7 @@ static int extract_name(struct dns_header *header, size_t plen, unsigned char **
|
|||||||
|
|
||||||
/* Max size of input string (for IPv6) is 75 chars.) */
|
/* Max size of input string (for IPv6) is 75 chars.) */
|
||||||
#define MAXARPANAME 75
|
#define MAXARPANAME 75
|
||||||
static int in_arpa_name_2_addr(char *namein, struct all_addr *addrp)
|
int in_arpa_name_2_addr(char *namein, struct all_addr *addrp)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
char name[MAXARPANAME+1], *cp1;
|
char name[MAXARPANAME+1], *cp1;
|
||||||
@@ -333,7 +329,7 @@ static unsigned char *skip_name(unsigned char *ansp, struct dns_header *header,
|
|||||||
return ansp;
|
return ansp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *skip_questions(struct dns_header *header, size_t plen)
|
unsigned char *skip_questions(struct dns_header *header, size_t plen)
|
||||||
{
|
{
|
||||||
int q;
|
int q;
|
||||||
unsigned char *ansp = (unsigned char *)(header+1);
|
unsigned char *ansp = (unsigned char *)(header+1);
|
||||||
@@ -699,15 +695,17 @@ static unsigned char *do_doctor(unsigned char *p, int count, struct dns_header *
|
|||||||
unsigned char *p2 = p1;
|
unsigned char *p2 = p1;
|
||||||
/* make counted string zero-term and sanitise */
|
/* make counted string zero-term and sanitise */
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
if (isprint(*(p2+1)))
|
{
|
||||||
{
|
if (!isprint((int)*(p2+1)))
|
||||||
*p2 = *(p2+1);
|
break;
|
||||||
p2++;
|
|
||||||
}
|
*p2 = *(p2+1);
|
||||||
|
p2++;
|
||||||
|
}
|
||||||
*p2 = 0;
|
*p2 = 0;
|
||||||
my_syslog(LOG_INFO, "reply %s is %s", name, p1);
|
my_syslog(LOG_INFO, "reply %s is %s", name, p1);
|
||||||
/* restore */
|
/* restore */
|
||||||
memmove(p1 + 1, p1, len);
|
memmove(p1 + 1, p1, i);
|
||||||
*p1 = len;
|
*p1 = len;
|
||||||
p1 += len+1;
|
p1 += len+1;
|
||||||
}
|
}
|
||||||
@@ -936,10 +934,14 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t
|
|||||||
if (!cname_count--)
|
if (!cname_count--)
|
||||||
return 0; /* looped CNAMES */
|
return 0; /* looped CNAMES */
|
||||||
newc = cache_insert(name, NULL, now, attl, F_CNAME | F_FORWARD);
|
newc = cache_insert(name, NULL, now, attl, F_CNAME | F_FORWARD);
|
||||||
if (newc && cpp)
|
if (newc)
|
||||||
{
|
{
|
||||||
cpp->addr.cname.cache = newc;
|
newc->addr.cname.cache = NULL;
|
||||||
cpp->addr.cname.uid = newc->uid;
|
if (cpp)
|
||||||
|
{
|
||||||
|
cpp->addr.cname.cache = newc;
|
||||||
|
cpp->addr.cname.uid = newc->uid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cpp = newc;
|
cpp = newc;
|
||||||
@@ -1003,10 +1005,16 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't put stuff from a truncated packet into the cache,
|
/* Don't put stuff from a truncated packet into the cache.
|
||||||
also don't cache replies where DNSSEC validation was turned off, either
|
Don't cache replies where DNSSEC validation was turned off, either
|
||||||
the upstream server told us so, or the original query specified it. */
|
the upstream server told us so, or the original query specified it.
|
||||||
if (!(header->hb3 & HB3_TC) && !(header->hb4 & HB4_CD) && !checking_disabled)
|
Don't cache replies from non-recursive nameservers, since we may get a
|
||||||
|
reply containing a CNAME but not its target, even though the target
|
||||||
|
does exist. */
|
||||||
|
if (!(header->hb3 & HB3_TC) &&
|
||||||
|
!(header->hb4 & HB4_CD) &&
|
||||||
|
(header->hb4 & HB4_RA) &&
|
||||||
|
!checking_disabled)
|
||||||
cache_end_insert();
|
cache_end_insert();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1177,8 +1185,8 @@ int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_resource_record(struct dns_header *header, char *limit, int *truncp, unsigned int nameoffset, unsigned char **pp,
|
int add_resource_record(struct dns_header *header, char *limit, int *truncp, int nameoffset, unsigned char **pp,
|
||||||
unsigned long ttl, unsigned int *offset, unsigned short type, unsigned short class, char *format, ...)
|
unsigned long ttl, int *offset, unsigned short type, unsigned short class, char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
unsigned char *sav, *p = *pp;
|
unsigned char *sav, *p = *pp;
|
||||||
@@ -1189,8 +1197,26 @@ static int add_resource_record(struct dns_header *header, char *limit, int *trun
|
|||||||
|
|
||||||
if (truncp && *truncp)
|
if (truncp && *truncp)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
va_start(ap, format); /* make ap point to 1st unamed argument */
|
||||||
|
|
||||||
|
if (nameoffset > 0)
|
||||||
|
{
|
||||||
|
PUTSHORT(nameoffset | 0xc000, p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *name = va_arg(ap, char *);
|
||||||
|
if (name)
|
||||||
|
p = do_rfc1035_name(p, name);
|
||||||
|
if (nameoffset < 0)
|
||||||
|
{
|
||||||
|
PUTSHORT(-nameoffset | 0xc000, p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*p++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
PUTSHORT(nameoffset | 0xc000, p);
|
|
||||||
PUTSHORT(type, p);
|
PUTSHORT(type, p);
|
||||||
PUTSHORT(class, p);
|
PUTSHORT(class, p);
|
||||||
PUTLONG(ttl, p); /* TTL */
|
PUTLONG(ttl, p); /* TTL */
|
||||||
@@ -1198,8 +1224,6 @@ static int add_resource_record(struct dns_header *header, char *limit, int *trun
|
|||||||
sav = p; /* Save pointer to RDLength field */
|
sav = p; /* Save pointer to RDLength field */
|
||||||
PUTSHORT(0, p); /* Placeholder RDLength */
|
PUTSHORT(0, p); /* Placeholder RDLength */
|
||||||
|
|
||||||
va_start(ap, format); /* make ap point to 1st unamed argument */
|
|
||||||
|
|
||||||
for (; *format; format++)
|
for (; *format; format++)
|
||||||
switch (*format)
|
switch (*format)
|
||||||
{
|
{
|
||||||
@@ -1238,7 +1262,8 @@ static int add_resource_record(struct dns_header *header, char *limit, int *trun
|
|||||||
case 't':
|
case 't':
|
||||||
usval = va_arg(ap, int);
|
usval = va_arg(ap, int);
|
||||||
sval = va_arg(ap, char *);
|
sval = va_arg(ap, char *);
|
||||||
memcpy(p, sval, usval);
|
if (usval != 0)
|
||||||
|
memcpy(p, sval, usval);
|
||||||
p += usval;
|
p += usval;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1294,7 +1319,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
unsigned char *p, *ansp, *pheader;
|
unsigned char *p, *ansp, *pheader;
|
||||||
int qtype, qclass;
|
int qtype, qclass;
|
||||||
struct all_addr addr;
|
struct all_addr addr;
|
||||||
unsigned int nameoffset;
|
int nameoffset;
|
||||||
unsigned short flag;
|
unsigned short flag;
|
||||||
int q, ans, anscount = 0, addncount = 0;
|
int q, ans, anscount = 0, addncount = 0;
|
||||||
int dryrun = 0, sec_reqd = 0;
|
int dryrun = 0, sec_reqd = 0;
|
||||||
@@ -1381,6 +1406,22 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
|
|
||||||
if (qclass == C_IN)
|
if (qclass == C_IN)
|
||||||
{
|
{
|
||||||
|
struct txt_record *t;
|
||||||
|
|
||||||
|
for (t = daemon->rr; t; t = t->next)
|
||||||
|
if ((t->class == qtype || qtype == T_ANY) && hostname_isequal(name, t->name))
|
||||||
|
{
|
||||||
|
ans = 1;
|
||||||
|
if (!dryrun)
|
||||||
|
{
|
||||||
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<RR>");
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
daemon->local_ttl, NULL,
|
||||||
|
t->class, C_IN, "t", t->len, t->txt))
|
||||||
|
anscount ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (qtype == T_PTR || qtype == T_ANY)
|
if (qtype == T_PTR || qtype == T_ANY)
|
||||||
{
|
{
|
||||||
/* see if it's w.z.y.z.in-addr.arpa format */
|
/* see if it's w.z.y.z.in-addr.arpa format */
|
||||||
@@ -1633,6 +1674,23 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
} while ((crecp = cache_find_by_name(crecp, name, now, flag | F_CNAME)));
|
} while ((crecp = cache_find_by_name(crecp, name, now, flag | F_CNAME)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (qtype == T_CNAME || qtype == T_ANY)
|
||||||
|
{
|
||||||
|
if ((crecp = cache_find_by_name(NULL, name, now, F_CNAME)) &&
|
||||||
|
(qtype == T_CNAME || (crecp->flags & (F_HOSTS | F_DHCP))))
|
||||||
|
{
|
||||||
|
ans = 1;
|
||||||
|
if (!dryrun)
|
||||||
|
{
|
||||||
|
log_query(crecp->flags, name, NULL, record_source(crecp->uid));
|
||||||
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
|
||||||
|
crec_ttl(crecp, now), &nameoffset,
|
||||||
|
T_CNAME, C_IN, "d", cache_get_name(crecp->addr.cname.cache)))
|
||||||
|
anscount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (qtype == T_MX || qtype == T_ANY)
|
if (qtype == T_MX || qtype == T_ANY)
|
||||||
{
|
{
|
||||||
@@ -1643,7 +1701,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
ans = found = 1;
|
ans = found = 1;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
{
|
{
|
||||||
unsigned int offset;
|
int offset;
|
||||||
log_query(F_CONFIG | F_RRNAME, name, NULL, "<MX>");
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<MX>");
|
||||||
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
|
||||||
&offset, T_MX, C_IN, "sd", rec->weight, rec->target))
|
&offset, T_MX, C_IN, "sd", rec->weight, rec->target))
|
||||||
@@ -1681,7 +1739,7 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
found = ans = 1;
|
found = ans = 1;
|
||||||
if (!dryrun)
|
if (!dryrun)
|
||||||
{
|
{
|
||||||
unsigned int offset;
|
int offset;
|
||||||
log_query(F_CONFIG | F_RRNAME, name, NULL, "<SRV>");
|
log_query(F_CONFIG | F_RRNAME, name, NULL, "<SRV>");
|
||||||
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
|
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
|
||||||
&offset, T_SRV, C_IN, "sssd",
|
&offset, T_SRV, C_IN, "sssd",
|
||||||
@@ -1811,7 +1869,3 @@ size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
|
|||||||
return ansp - (unsigned char *)header;
|
return ansp - (unsigned char *)header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+112
-268
@@ -18,16 +18,13 @@
|
|||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
|
|
||||||
#define have_config(config, mask) ((config) && ((config)->flags & (mask)))
|
|
||||||
#define option_len(opt) ((int)(((unsigned char *)(opt))[1]))
|
#define option_len(opt) ((int)(((unsigned char *)(opt))[1]))
|
||||||
#define option_ptr(opt, i) ((void *)&(((unsigned char *)(opt))[2u+(unsigned int)(i)]))
|
#define option_ptr(opt, i) ((void *)&(((unsigned char *)(opt))[2u+(unsigned int)(i)]))
|
||||||
|
|
||||||
#ifdef HAVE_SCRIPT
|
#ifdef HAVE_SCRIPT
|
||||||
static void add_extradata_data(struct dhcp_lease *lease, unsigned char *data, size_t len, int delim);
|
|
||||||
static void add_extradata_opt(struct dhcp_lease *lease, unsigned char *opt);
|
static void add_extradata_opt(struct dhcp_lease *lease, unsigned char *opt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int match_bytes(struct dhcp_opt *o, unsigned char *p, int len);
|
|
||||||
static int sanitise(unsigned char *opt, char *buf);
|
static int sanitise(unsigned char *opt, char *buf);
|
||||||
static struct in_addr server_id(struct dhcp_context *context, struct in_addr override, struct in_addr fallback);
|
static struct in_addr server_id(struct dhcp_context *context, struct in_addr override, struct in_addr fallback);
|
||||||
static unsigned int calc_time(struct dhcp_context *context, struct dhcp_config *config, unsigned char *opt);
|
static unsigned int calc_time(struct dhcp_context *context, struct dhcp_config *config, unsigned char *opt);
|
||||||
@@ -35,13 +32,11 @@ static void option_put(struct dhcp_packet *mess, unsigned char *end, int opt, in
|
|||||||
static void option_put_string(struct dhcp_packet *mess, unsigned char *end,
|
static void option_put_string(struct dhcp_packet *mess, unsigned char *end,
|
||||||
int opt, char *string, int null_term);
|
int opt, char *string, int null_term);
|
||||||
static struct in_addr option_addr(unsigned char *opt);
|
static struct in_addr option_addr(unsigned char *opt);
|
||||||
static struct in_addr option_addr_arr(unsigned char *opt, int offset);
|
|
||||||
static unsigned int option_uint(unsigned char *opt, int i, int size);
|
static unsigned int option_uint(unsigned char *opt, int i, int size);
|
||||||
static void log_packet(char *type, void *addr, unsigned char *ext_mac,
|
static void log_packet(char *type, void *addr, unsigned char *ext_mac,
|
||||||
int mac_len, char *interface, char *string, u32 xid);
|
int mac_len, char *interface, char *string, u32 xid);
|
||||||
static unsigned char *option_find(struct dhcp_packet *mess, size_t size, int opt_type, int minsize);
|
static unsigned char *option_find(struct dhcp_packet *mess, size_t size, int opt_type, int minsize);
|
||||||
static unsigned char *option_find1(unsigned char *p, unsigned char *end, int opt, int minsize);
|
static unsigned char *option_find1(unsigned char *p, unsigned char *end, int opt, int minsize);
|
||||||
static void log_tags(struct dhcp_netid *netid, struct dhcp_packet *mess);
|
|
||||||
static size_t dhcp_packet_size(struct dhcp_packet *mess, unsigned char *agent_id, unsigned char *real_end);
|
static size_t dhcp_packet_size(struct dhcp_packet *mess, unsigned char *agent_id, unsigned char *real_end);
|
||||||
static void clear_packet(struct dhcp_packet *mess, unsigned char *end);
|
static void clear_packet(struct dhcp_packet *mess, unsigned char *end);
|
||||||
static void do_options(struct dhcp_context *context,
|
static void do_options(struct dhcp_context *context,
|
||||||
@@ -49,7 +44,7 @@ static void do_options(struct dhcp_context *context,
|
|||||||
unsigned char *real_end,
|
unsigned char *real_end,
|
||||||
unsigned char *req_options,
|
unsigned char *req_options,
|
||||||
char *hostname,
|
char *hostname,
|
||||||
char *domain, char *config_domain,
|
char *config_domain,
|
||||||
struct dhcp_netid *netid,
|
struct dhcp_netid *netid,
|
||||||
struct in_addr subnet_addr,
|
struct in_addr subnet_addr,
|
||||||
unsigned char fqdn_flags,
|
unsigned char fqdn_flags,
|
||||||
@@ -63,7 +58,7 @@ static void match_vendor_opts(unsigned char *opt, struct dhcp_opt *dopt);
|
|||||||
static int do_encap_opts(struct dhcp_opt *opts, int encap, int flag, struct dhcp_packet *mess, unsigned char *end, int null_term);
|
static int do_encap_opts(struct dhcp_opt *opts, int encap, int flag, struct dhcp_packet *mess, unsigned char *end, int null_term);
|
||||||
static void pxe_misc(struct dhcp_packet *mess, unsigned char *end, unsigned char *uuid);
|
static void pxe_misc(struct dhcp_packet *mess, unsigned char *end, unsigned char *uuid);
|
||||||
static int prune_vendor_opts(struct dhcp_netid *netid);
|
static int prune_vendor_opts(struct dhcp_netid *netid);
|
||||||
static struct dhcp_opt *pxe_opts(int pxe_arch, struct dhcp_netid *netid, struct in_addr local);
|
static struct dhcp_opt *pxe_opts(int pxe_arch, struct dhcp_netid *netid, struct in_addr local, time_t now);
|
||||||
struct dhcp_boot *find_boot(struct dhcp_netid *netid);
|
struct dhcp_boot *find_boot(struct dhcp_netid *netid);
|
||||||
|
|
||||||
|
|
||||||
@@ -468,7 +463,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
tagif_netid = run_tag_if(&context->netid);
|
tagif_netid = run_tag_if(&context->netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_tags(tagif_netid, mess);
|
log_tags(tagif_netid, ntohl(mess->xid));
|
||||||
|
|
||||||
if (!message && !nailed)
|
if (!message && !nailed)
|
||||||
{
|
{
|
||||||
@@ -481,25 +476,26 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
|
|
||||||
if (!message &&
|
if (!message &&
|
||||||
!lease &&
|
!lease &&
|
||||||
(!(lease = lease_allocate4(mess->yiaddr))))
|
(!(lease = lease4_allocate(mess->yiaddr))))
|
||||||
message = _("no leases left");
|
message = _("no leases left");
|
||||||
|
|
||||||
if (!message)
|
if (!message)
|
||||||
{
|
{
|
||||||
logaddr = &mess->yiaddr;
|
logaddr = &mess->yiaddr;
|
||||||
|
|
||||||
lease_set_hwaddr(lease, mess->chaddr, NULL, mess->hlen, mess->htype, 0);
|
lease_set_hwaddr(lease, mess->chaddr, NULL, mess->hlen, mess->htype, 0, now, 1);
|
||||||
if (hostname)
|
if (hostname)
|
||||||
lease_set_hostname(lease, hostname, 1);
|
lease_set_hostname(lease, hostname, 1, get_domain(lease->addr), domain);
|
||||||
/* infinite lease unless nailed in dhcp-host line. */
|
/* infinite lease unless nailed in dhcp-host line. */
|
||||||
lease_set_expires(lease,
|
lease_set_expires(lease,
|
||||||
have_config(config, CONFIG_TIME) ? config->lease_time : 0xffffffff,
|
have_config(config, CONFIG_TIME) ? config->lease_time : 0xffffffff,
|
||||||
now);
|
now);
|
||||||
lease_set_interface(lease, int_index);
|
lease_set_interface(lease, int_index, now);
|
||||||
|
|
||||||
clear_packet(mess, end);
|
clear_packet(mess, end);
|
||||||
|
match_vendor_opts(NULL, daemon->dhcp_opts); /* clear flags */
|
||||||
do_options(context, mess, end, NULL, hostname, get_domain(mess->yiaddr),
|
do_options(context, mess, end, NULL, hostname, get_domain(mess->yiaddr),
|
||||||
domain, netid, subnet_addr, 0, 0, 0, NULL, 0, now);
|
netid, subnet_addr, 0, 0, -1, NULL, 0, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,11 +516,22 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
op += 3;
|
op += 3;
|
||||||
pp = op;
|
pp = op;
|
||||||
|
|
||||||
/* Always force update, since the client has no way to do it itself. */
|
/* NB, the following always sets at least one bit */
|
||||||
if (!option_bool(OPT_FQDN_UPDATE) && !(fqdn_flags & 0x01))
|
if (option_bool(OPT_FQDN_UPDATE))
|
||||||
fqdn_flags |= 0x03;
|
{
|
||||||
|
if (fqdn_flags & 0x01)
|
||||||
fqdn_flags &= ~0x08;
|
{
|
||||||
|
fqdn_flags |= 0x02; /* set O */
|
||||||
|
fqdn_flags &= ~0x01; /* clear S */
|
||||||
|
}
|
||||||
|
fqdn_flags |= 0x08; /* set N */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(fqdn_flags & 0x01))
|
||||||
|
fqdn_flags |= 0x03; /* set S and O */
|
||||||
|
fqdn_flags &= ~0x08; /* clear N */
|
||||||
|
}
|
||||||
|
|
||||||
if (fqdn_flags & 0x04)
|
if (fqdn_flags & 0x04)
|
||||||
while (*op != 0 && ((op + (*op) + 1) - pp) < len)
|
while (*op != 0 && ((op + (*op) + 1) - pp) < len)
|
||||||
@@ -799,7 +806,9 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
|
|
||||||
mess->yiaddr = mess->ciaddr;
|
mess->yiaddr = mess->ciaddr;
|
||||||
mess->ciaddr.s_addr = 0;
|
mess->ciaddr.s_addr = 0;
|
||||||
if (service->server.s_addr != 0)
|
if (service->sname)
|
||||||
|
mess->siaddr = a_record_from_hosts(service->sname, now);
|
||||||
|
else if (service->server.s_addr != 0)
|
||||||
mess->siaddr = service->server;
|
mess->siaddr = service->server;
|
||||||
else
|
else
|
||||||
mess->siaddr = context->local;
|
mess->siaddr = context->local;
|
||||||
@@ -819,7 +828,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
do_encap_opts(&opt71, OPTION_VENDOR_CLASS_OPT, DHOPT_VENDOR_MATCH, mess, end, 0);
|
do_encap_opts(&opt71, OPTION_VENDOR_CLASS_OPT, DHOPT_VENDOR_MATCH, mess, end, 0);
|
||||||
|
|
||||||
log_packet("PXE", &mess->yiaddr, emac, emac_len, iface_name, (char *)mess->file, mess->xid);
|
log_packet("PXE", &mess->yiaddr, emac, emac_len, iface_name, (char *)mess->file, mess->xid);
|
||||||
log_tags(tagif_netid, mess);
|
log_tags(tagif_netid, ntohl(mess->xid));
|
||||||
return dhcp_packet_size(mess, agent_id, real_end);
|
return dhcp_packet_size(mess, agent_id, real_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,10 +877,10 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, htonl(context->local.s_addr));
|
option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, htonl(context->local.s_addr));
|
||||||
pxe_misc(mess, end, uuid);
|
pxe_misc(mess, end, uuid);
|
||||||
prune_vendor_opts(tagif_netid);
|
prune_vendor_opts(tagif_netid);
|
||||||
do_encap_opts(pxe_opts(pxearch, tagif_netid, context->local), OPTION_VENDOR_CLASS_OPT, DHOPT_VENDOR_MATCH, mess, end, 0);
|
do_encap_opts(pxe_opts(pxearch, tagif_netid, context->local, now), OPTION_VENDOR_CLASS_OPT, DHOPT_VENDOR_MATCH, mess, end, 0);
|
||||||
|
|
||||||
log_packet("PXE", NULL, emac, emac_len, iface_name, ignore ? "proxy-ignored" : "proxy", mess->xid);
|
log_packet("PXE", NULL, emac, emac_len, iface_name, ignore ? "proxy-ignored" : "proxy", mess->xid);
|
||||||
log_tags(tagif_netid, mess);
|
log_tags(tagif_netid, ntohl(mess->xid));
|
||||||
return ignore ? 0 : dhcp_packet_size(mess, agent_id, real_end);
|
return ignore ? 0 : dhcp_packet_size(mess, agent_id, real_end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1009,7 +1018,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
tagif_netid = run_tag_if(&context->netid);
|
tagif_netid = run_tag_if(&context->netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_tags(tagif_netid, mess);
|
log_tags(tagif_netid, ntohl(mess->xid));
|
||||||
|
|
||||||
log_packet("DHCPOFFER" , &mess->yiaddr, emac, emac_len, iface_name, NULL, mess->xid);
|
log_packet("DHCPOFFER" , &mess->yiaddr, emac, emac_len, iface_name, NULL, mess->xid);
|
||||||
|
|
||||||
@@ -1025,7 +1034,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
option_put(mess, end, OPTION_T2, 4, (time*7)/8);
|
option_put(mess, end, OPTION_T2, 4, (time*7)/8);
|
||||||
}
|
}
|
||||||
do_options(context, mess, end, req_options, offer_hostname, get_domain(mess->yiaddr),
|
do_options(context, mess, end, req_options, offer_hostname, get_domain(mess->yiaddr),
|
||||||
domain, netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
||||||
|
|
||||||
return dhcp_packet_size(mess, agent_id, real_end);
|
return dhcp_packet_size(mess, agent_id, real_end);
|
||||||
|
|
||||||
@@ -1189,7 +1198,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
|
|
||||||
else if (!lease)
|
else if (!lease)
|
||||||
{
|
{
|
||||||
if ((lease = lease_allocate4(mess->yiaddr)))
|
if ((lease = lease4_allocate(mess->yiaddr)))
|
||||||
do_classes = 1;
|
do_classes = 1;
|
||||||
else
|
else
|
||||||
message = _("no leases left");
|
message = _("no leases left");
|
||||||
@@ -1223,53 +1232,58 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
tagif_netid = run_tag_if( &context->netid);
|
tagif_netid = run_tag_if( &context->netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_tags(tagif_netid, mess);
|
log_tags(tagif_netid, ntohl(mess->xid));
|
||||||
|
|
||||||
#ifdef HAVE_SCRIPT
|
if (do_classes)
|
||||||
if (do_classes && daemon->lease_change_command)
|
|
||||||
{
|
{
|
||||||
struct dhcp_netid *n;
|
/* pick up INIT-REBOOT events. */
|
||||||
|
lease->flags |= LEASE_CHANGED;
|
||||||
if (mess->giaddr.s_addr)
|
|
||||||
lease->giaddr = mess->giaddr;
|
|
||||||
|
|
||||||
lease->changed = 1;
|
|
||||||
free(lease->extradata);
|
|
||||||
lease->extradata = NULL;
|
|
||||||
lease->extradata_size = lease->extradata_len = 0;
|
|
||||||
|
|
||||||
add_extradata_opt(lease, option_find(mess, sz, OPTION_VENDOR_ID, 1));
|
|
||||||
add_extradata_opt(lease, option_find(mess, sz, OPTION_HOSTNAME, 1));
|
|
||||||
add_extradata_opt(lease, oui);
|
|
||||||
add_extradata_opt(lease, serial);
|
|
||||||
add_extradata_opt(lease, class);
|
|
||||||
|
|
||||||
/* space-concat tag set */
|
|
||||||
if (!tagif_netid)
|
|
||||||
add_extradata_opt(lease, NULL);
|
|
||||||
else
|
|
||||||
for (n = tagif_netid; n; n = n->next)
|
|
||||||
{
|
|
||||||
struct dhcp_netid *n1;
|
|
||||||
/* kill dupes */
|
|
||||||
for (n1 = n->next; n1; n1 = n1->next)
|
|
||||||
if (strcmp(n->net, n1->net) == 0)
|
|
||||||
break;
|
|
||||||
if (!n1)
|
|
||||||
add_extradata_data(lease, (unsigned char *)n->net, strlen(n->net), n->next ? ' ' : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((opt = option_find(mess, sz, OPTION_USER_CLASS, 1)))
|
#ifdef HAVE_SCRIPT
|
||||||
|
if (daemon->lease_change_command)
|
||||||
{
|
{
|
||||||
int len = option_len(opt);
|
struct dhcp_netid *n;
|
||||||
unsigned char *ucp = option_ptr(opt, 0);
|
|
||||||
/* If the user-class option started as counted strings, the first byte will be zero. */
|
if (mess->giaddr.s_addr)
|
||||||
if (len != 0 && ucp[0] == 0)
|
lease->giaddr = mess->giaddr;
|
||||||
ucp++, len--;
|
|
||||||
add_extradata_data(lease, ucp, len, 0);
|
free(lease->extradata);
|
||||||
|
lease->extradata = NULL;
|
||||||
|
lease->extradata_size = lease->extradata_len = 0;
|
||||||
|
|
||||||
|
add_extradata_opt(lease, option_find(mess, sz, OPTION_VENDOR_ID, 1));
|
||||||
|
add_extradata_opt(lease, option_find(mess, sz, OPTION_HOSTNAME, 1));
|
||||||
|
add_extradata_opt(lease, oui);
|
||||||
|
add_extradata_opt(lease, serial);
|
||||||
|
add_extradata_opt(lease, class);
|
||||||
|
|
||||||
|
/* space-concat tag set */
|
||||||
|
if (!tagif_netid)
|
||||||
|
add_extradata_opt(lease, NULL);
|
||||||
|
else
|
||||||
|
for (n = tagif_netid; n; n = n->next)
|
||||||
|
{
|
||||||
|
struct dhcp_netid *n1;
|
||||||
|
/* kill dupes */
|
||||||
|
for (n1 = n->next; n1; n1 = n1->next)
|
||||||
|
if (strcmp(n->net, n1->net) == 0)
|
||||||
|
break;
|
||||||
|
if (!n1)
|
||||||
|
lease_add_extradata(lease, (unsigned char *)n->net, strlen(n->net), n->next ? ' ' : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((opt = option_find(mess, sz, OPTION_USER_CLASS, 1)))
|
||||||
|
{
|
||||||
|
int len = option_len(opt);
|
||||||
|
unsigned char *ucp = option_ptr(opt, 0);
|
||||||
|
/* If the user-class option started as counted strings, the first byte will be zero. */
|
||||||
|
if (len != 0 && ucp[0] == 0)
|
||||||
|
ucp++, len--;
|
||||||
|
lease_add_extradata(lease, ucp, len, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (!hostname_auth && (client_hostname = host_from_dns(mess->yiaddr)))
|
if (!hostname_auth && (client_hostname = host_from_dns(mess->yiaddr)))
|
||||||
{
|
{
|
||||||
@@ -1279,7 +1293,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
time = calc_time(context, config, option_find(mess, sz, OPTION_LEASE_TIME, 4));
|
time = calc_time(context, config, option_find(mess, sz, OPTION_LEASE_TIME, 4));
|
||||||
lease_set_hwaddr(lease, mess->chaddr, clid, mess->hlen, mess->htype, clid_len);
|
lease_set_hwaddr(lease, mess->chaddr, clid, mess->hlen, mess->htype, clid_len, now, do_classes);
|
||||||
|
|
||||||
/* if all the netids in the ignore_name list are present, ignore client-supplied name */
|
/* if all the netids in the ignore_name list are present, ignore client-supplied name */
|
||||||
if (!hostname_auth)
|
if (!hostname_auth)
|
||||||
@@ -1310,10 +1324,10 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hostname)
|
if (hostname)
|
||||||
lease_set_hostname(lease, hostname, hostname_auth);
|
lease_set_hostname(lease, hostname, hostname_auth, get_domain(lease->addr), domain);
|
||||||
|
|
||||||
lease_set_expires(lease, time, now);
|
lease_set_expires(lease, time, now);
|
||||||
lease_set_interface(lease, int_index);
|
lease_set_interface(lease, int_index, now);
|
||||||
|
|
||||||
if (override.s_addr != 0)
|
if (override.s_addr != 0)
|
||||||
lease->override = override;
|
lease->override = override;
|
||||||
@@ -1334,7 +1348,7 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
option_put(mess, end, OPTION_T2, 4, ((time/8)*7) - fuzz);
|
option_put(mess, end, OPTION_T2, 4, ((time/8)*7) - fuzz);
|
||||||
}
|
}
|
||||||
do_options(context, mess, end, req_options, hostname, get_domain(mess->yiaddr),
|
do_options(context, mess, end, req_options, hostname, get_domain(mess->yiaddr),
|
||||||
domain, netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dhcp_packet_size(mess, agent_id, real_end);
|
return dhcp_packet_size(mess, agent_id, real_end);
|
||||||
@@ -1364,15 +1378,16 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
if (context && context->netid.net)
|
if (context && context->netid.net)
|
||||||
{
|
{
|
||||||
context->netid.next = netid;
|
context->netid.next = netid;
|
||||||
tagif_netid = run_tag_if( &context->netid);
|
tagif_netid = run_tag_if(&context->netid);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_tags(tagif_netid, mess);
|
log_tags(tagif_netid, ntohl(mess->xid));
|
||||||
|
|
||||||
log_packet("DHCPACK", &mess->ciaddr, emac, emac_len, iface_name, hostname, mess->xid);
|
log_packet("DHCPACK", &mess->ciaddr, emac, emac_len, iface_name, hostname, mess->xid);
|
||||||
|
|
||||||
if (lease)
|
if (lease)
|
||||||
{
|
{
|
||||||
|
lease_set_interface(lease, int_index, now);
|
||||||
if (override.s_addr != 0)
|
if (override.s_addr != 0)
|
||||||
lease->override = override;
|
lease->override = override;
|
||||||
else
|
else
|
||||||
@@ -1383,18 +1398,8 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
option_put(mess, end, OPTION_MESSAGE_TYPE, 1, DHCPACK);
|
option_put(mess, end, OPTION_MESSAGE_TYPE, 1, DHCPACK);
|
||||||
option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, ntohl(server_id(context, override, fallback).s_addr));
|
option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, ntohl(server_id(context, override, fallback).s_addr));
|
||||||
|
|
||||||
if (lease)
|
|
||||||
{
|
|
||||||
if (lease->expires == 0)
|
|
||||||
time = 0xffffffff;
|
|
||||||
else
|
|
||||||
time = (unsigned int)difftime(lease->expires, now);
|
|
||||||
option_put(mess, end, OPTION_LEASE_TIME, 4, time);
|
|
||||||
lease_set_interface(lease, int_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
do_options(context, mess, end, req_options, hostname, get_domain(mess->ciaddr),
|
do_options(context, mess, end, req_options, hostname, get_domain(mess->ciaddr),
|
||||||
domain, netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
||||||
|
|
||||||
*is_inform = 1; /* handle reply differently */
|
*is_inform = 1; /* handle reply differently */
|
||||||
return dhcp_packet_size(mess, agent_id, real_end);
|
return dhcp_packet_size(mess, agent_id, real_end);
|
||||||
@@ -1403,37 +1408,6 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match_bytes(struct dhcp_opt *o, unsigned char *p, int len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (o->len > len)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (o->len == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (o->flags & DHOPT_HEX)
|
|
||||||
{
|
|
||||||
if (memcmp_masked(o->val, p, o->len, o->u.wildcard_mask))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (i = 0; i <= (len - o->len); )
|
|
||||||
{
|
|
||||||
if (memcmp(o->val, p + i, o->len) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (o->flags & DHOPT_STRING)
|
|
||||||
i++;
|
|
||||||
else
|
|
||||||
i += o->len;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* find a good value to use as MAC address for logging and address-allocation hashing.
|
/* find a good value to use as MAC address for logging and address-allocation hashing.
|
||||||
This is normally just the chaddr field from the DHCP packet,
|
This is normally just the chaddr field from the DHCP packet,
|
||||||
but eg Firewire will have hlen == 0 and use the client-id instead.
|
but eg Firewire will have hlen == 0 and use the client-id instead.
|
||||||
@@ -1519,51 +1493,12 @@ static int sanitise(unsigned char *opt, char *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SCRIPT
|
#ifdef HAVE_SCRIPT
|
||||||
static void add_extradata_data(struct dhcp_lease *lease, unsigned char *data, size_t len, int delim)
|
|
||||||
{
|
|
||||||
if ((lease->extradata_size - lease->extradata_len) < (len + 1))
|
|
||||||
{
|
|
||||||
size_t newsz = lease->extradata_len + len + 100;
|
|
||||||
unsigned char *new = whine_malloc(newsz);
|
|
||||||
|
|
||||||
if (!new)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (lease->extradata)
|
|
||||||
{
|
|
||||||
memcpy(new, lease->extradata, lease->extradata_len);
|
|
||||||
free(lease->extradata);
|
|
||||||
}
|
|
||||||
|
|
||||||
lease->extradata = new;
|
|
||||||
lease->extradata_size = newsz;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len != 0)
|
|
||||||
memcpy(lease->extradata + lease->extradata_len, data, len);
|
|
||||||
lease->extradata[lease->extradata_len + len] = delim;
|
|
||||||
lease->extradata_len += len + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add_extradata_opt(struct dhcp_lease *lease, unsigned char *opt)
|
static void add_extradata_opt(struct dhcp_lease *lease, unsigned char *opt)
|
||||||
{
|
{
|
||||||
if (!opt)
|
if (!opt)
|
||||||
add_extradata_data(lease, NULL, 0, 0);
|
lease_add_extradata(lease, NULL, 0, 0);
|
||||||
else
|
else
|
||||||
{
|
lease_add_extradata(lease, option_ptr(opt, 0), option_len(opt), 0);
|
||||||
size_t i, len = option_len(opt);
|
|
||||||
unsigned char *ucp = option_ptr(opt, 0);
|
|
||||||
|
|
||||||
/* check for embeded NULLs */
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
if (ucp[i] == 0)
|
|
||||||
{
|
|
||||||
len = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_extradata_data(lease, ucp, len, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1601,30 +1536,10 @@ static void log_options(unsigned char *start, u32 xid)
|
|||||||
{
|
{
|
||||||
while (*start != OPTION_END)
|
while (*start != OPTION_END)
|
||||||
{
|
{
|
||||||
int is_ip, is_name, i;
|
char *optname = option_string(AF_INET, start[0], option_ptr(start, 0), option_len(start), daemon->namebuff, MAXDNAME);
|
||||||
char *text = option_string(start[0], &is_ip, &is_name);
|
|
||||||
unsigned char trunc = option_len(start);
|
|
||||||
|
|
||||||
if (is_ip)
|
my_syslog(MS_DHCP | LOG_INFO, "%u sent size:%3d option:%3d %s %s",
|
||||||
for (daemon->namebuff[0]= 0, i = 0; i <= trunc - INADDRSZ; i += INADDRSZ)
|
ntohl(xid), option_len(start), start[0], optname, daemon->namebuff);
|
||||||
{
|
|
||||||
if (i != 0)
|
|
||||||
strncat(daemon->namebuff, ", ", 256 - strlen(daemon->namebuff));
|
|
||||||
strncat(daemon->namebuff, inet_ntoa(option_addr_arr(start, i)), 256 - strlen(daemon->namebuff));
|
|
||||||
}
|
|
||||||
else if (!is_name || !sanitise(start, daemon->namebuff))
|
|
||||||
{
|
|
||||||
if (trunc > 13)
|
|
||||||
trunc = 13;
|
|
||||||
print_mac(daemon->namebuff, option_ptr(start, 0), trunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
my_syslog(MS_DHCP | LOG_INFO, "%u sent size:%3d option:%3d%s%s%s%s%s",
|
|
||||||
ntohl(xid), option_len(start), start[0],
|
|
||||||
text ? ":" : "", text ? text : "",
|
|
||||||
trunc == 0 ? "" : " ",
|
|
||||||
trunc == 0 ? "" : daemon->namebuff,
|
|
||||||
trunc == option_len(start) ? "" : "...");
|
|
||||||
start += start[1] + 2;
|
start += start[1] + 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1679,22 +1594,17 @@ static unsigned char *option_find(struct dhcp_packet *mess, size_t size, int opt
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct in_addr option_addr_arr(unsigned char *opt, int offset)
|
static struct in_addr option_addr(unsigned char *opt)
|
||||||
{
|
{
|
||||||
/* this worries about unaligned data in the option. */
|
/* this worries about unaligned data in the option. */
|
||||||
/* struct in_addr is network byte order */
|
/* struct in_addr is network byte order */
|
||||||
struct in_addr ret;
|
struct in_addr ret;
|
||||||
|
|
||||||
memcpy(&ret, option_ptr(opt, offset), INADDRSZ);
|
memcpy(&ret, option_ptr(opt, 0), INADDRSZ);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct in_addr option_addr(unsigned char *opt)
|
|
||||||
{
|
|
||||||
return option_addr_arr(opt, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned int option_uint(unsigned char *opt, int offset, int size)
|
static unsigned int option_uint(unsigned char *opt, int offset, int size)
|
||||||
{
|
{
|
||||||
/* this worries about unaligned data and byte order */
|
/* this worries about unaligned data and byte order */
|
||||||
@@ -1729,31 +1639,6 @@ static unsigned char *find_overload(struct dhcp_packet *mess)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_tags(struct dhcp_netid *netid, struct dhcp_packet *mess)
|
|
||||||
{
|
|
||||||
if (netid && option_bool(OPT_LOG_OPTS))
|
|
||||||
{
|
|
||||||
char *s = daemon->namebuff;
|
|
||||||
for (*s = 0; netid; netid = netid->next)
|
|
||||||
{
|
|
||||||
/* kill dupes. */
|
|
||||||
struct dhcp_netid *n;
|
|
||||||
|
|
||||||
for (n = netid->next; n; n = n->next)
|
|
||||||
if (strcmp(netid->net, n->net) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!n)
|
|
||||||
{
|
|
||||||
strncat (s, netid->net, (MAXDNAME-1) - strlen(s));
|
|
||||||
if (netid->next)
|
|
||||||
strncat (s, ", ", (MAXDNAME-1) - strlen(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
my_syslog(MS_DHCP | LOG_INFO, _("%u tags: %s"), ntohl(mess->xid), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t dhcp_packet_size(struct dhcp_packet *mess, unsigned char *agent_id, unsigned char *real_end)
|
static size_t dhcp_packet_size(struct dhcp_packet *mess, unsigned char *agent_id, unsigned char *real_end)
|
||||||
{
|
{
|
||||||
unsigned char *p = dhcp_skip_opts(&mess->options[0] + sizeof(u32));
|
unsigned char *p = dhcp_skip_opts(&mess->options[0] + sizeof(u32));
|
||||||
@@ -2048,7 +1933,7 @@ static int prune_vendor_opts(struct dhcp_netid *netid)
|
|||||||
return force;
|
return force;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dhcp_opt *pxe_opts(int pxe_arch, struct dhcp_netid *netid, struct in_addr local)
|
static struct dhcp_opt *pxe_opts(int pxe_arch, struct dhcp_netid *netid, struct in_addr local, time_t now)
|
||||||
{
|
{
|
||||||
#define NUM_OPTS 4
|
#define NUM_OPTS 4
|
||||||
|
|
||||||
@@ -2105,8 +1990,9 @@ static struct dhcp_opt *pxe_opts(int pxe_arch, struct dhcp_netid *netid, struct
|
|||||||
return daemon->dhcp_opts;
|
return daemon->dhcp_opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_server = service->basename ? local : service->server;
|
boot_server = service->basename ? local :
|
||||||
|
(service->sname ? a_record_from_hosts(service->sname, now) : service->server);
|
||||||
|
|
||||||
if (boot_server.s_addr != 0)
|
if (boot_server.s_addr != 0)
|
||||||
{
|
{
|
||||||
if (q - (unsigned char *)daemon->dhcp_buff3 + 3 + INADDRSZ >= 253)
|
if (q - (unsigned char *)daemon->dhcp_buff3 + 3 + INADDRSZ >= 253)
|
||||||
@@ -2197,7 +2083,7 @@ static void do_options(struct dhcp_context *context,
|
|||||||
unsigned char *end,
|
unsigned char *end,
|
||||||
unsigned char *req_options,
|
unsigned char *req_options,
|
||||||
char *hostname,
|
char *hostname,
|
||||||
char *domain, char *config_domain,
|
char *domain,
|
||||||
struct dhcp_netid *netid,
|
struct dhcp_netid *netid,
|
||||||
struct in_addr subnet_addr,
|
struct in_addr subnet_addr,
|
||||||
unsigned char fqdn_flags,
|
unsigned char fqdn_flags,
|
||||||
@@ -2216,65 +2102,23 @@ static void do_options(struct dhcp_context *context,
|
|||||||
struct dhcp_netid *tagif;
|
struct dhcp_netid *tagif;
|
||||||
struct dhcp_netid_list *id_list;
|
struct dhcp_netid_list *id_list;
|
||||||
|
|
||||||
/* flag options which are valid with the current tag set (sans context tags) */
|
/* filter options based on tags, those we want get DHOPT_TAGOK bit set */
|
||||||
tagif = run_tag_if(netid);
|
if (context)
|
||||||
for (opt = config_opts; opt; opt = opt->next)
|
context->netid.next = NULL;
|
||||||
{
|
tagif = option_filter(netid, context && context->netid.net ? &context->netid : NULL, config_opts);
|
||||||
opt->flags &= ~DHOPT_TAGOK;
|
|
||||||
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) &&
|
|
||||||
match_netid(opt->netid, tagif, 0))
|
|
||||||
opt->flags |= DHOPT_TAGOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now flag options which are valid, including the context tags,
|
|
||||||
otherwise valid options are inhibited if we found a higher priotity one above */
|
|
||||||
if (context && context->netid.net)
|
|
||||||
{
|
|
||||||
context->netid.next = netid;
|
|
||||||
tagif = run_tag_if(&context->netid);
|
|
||||||
|
|
||||||
for (opt = config_opts; opt; opt = opt->next)
|
|
||||||
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925 | DHOPT_TAGOK)) &&
|
|
||||||
match_netid(opt->netid, tagif, 0))
|
|
||||||
{
|
|
||||||
struct dhcp_opt *tmp;
|
|
||||||
for (tmp = config_opts; tmp; tmp = tmp->next)
|
|
||||||
if (tmp->opt == opt->opt && opt->netid && (tmp->flags & DHOPT_TAGOK))
|
|
||||||
break;
|
|
||||||
if (!tmp)
|
|
||||||
opt->flags |= DHOPT_TAGOK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now flag untagged options which are not overridden by tagged ones */
|
|
||||||
for (opt = config_opts; opt; opt = opt->next)
|
|
||||||
if (!(opt->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925 | DHOPT_TAGOK)) && !opt->netid)
|
|
||||||
{
|
|
||||||
struct dhcp_opt *tmp;
|
|
||||||
for (tmp = config_opts; tmp; tmp = tmp->next)
|
|
||||||
if (tmp->opt == opt->opt && (tmp->flags & DHOPT_TAGOK))
|
|
||||||
break;
|
|
||||||
if (!tmp)
|
|
||||||
opt->flags |= DHOPT_TAGOK;
|
|
||||||
else if (!tmp->netid)
|
|
||||||
my_syslog(MS_DHCP | LOG_WARNING, _("Ignoring duplicate dhcp-option %d"), tmp->opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config_domain && (!domain || !hostname_isequal(domain, config_domain)))
|
|
||||||
my_syslog(MS_DHCP | LOG_WARNING, _("Ignoring domain %s for DHCP host name %s"), config_domain, hostname);
|
|
||||||
|
|
||||||
/* logging */
|
/* logging */
|
||||||
if (option_bool(OPT_LOG_OPTS) && req_options)
|
if (option_bool(OPT_LOG_OPTS) && req_options)
|
||||||
{
|
{
|
||||||
char *q = daemon->namebuff;
|
char *q = daemon->namebuff;
|
||||||
for (i = 0; req_options[i] != OPTION_END; i++)
|
for (i = 0; req_options[i] != OPTION_END; i++)
|
||||||
{
|
{
|
||||||
char *s = option_string(req_options[i], NULL, NULL);
|
char *s = option_string(AF_INET, req_options[i], NULL, 0, NULL, 0);
|
||||||
q += snprintf(q, MAXDNAME - (q - daemon->namebuff),
|
q += snprintf(q, MAXDNAME - (q - daemon->namebuff),
|
||||||
"%d%s%s%s",
|
"%d%s%s%s",
|
||||||
req_options[i],
|
req_options[i],
|
||||||
s ? ":" : "",
|
strlen(s) != 0 ? ":" : "",
|
||||||
s ? s : "",
|
s,
|
||||||
req_options[i+1] == OPTION_END ? "" : ", ");
|
req_options[i+1] == OPTION_END ? "" : ", ");
|
||||||
if (req_options[i+1] == OPTION_END || (q - daemon->namebuff) > 40)
|
if (req_options[i+1] == OPTION_END || (q - daemon->namebuff) > 40)
|
||||||
{
|
{
|
||||||
@@ -2420,7 +2264,7 @@ static void do_options(struct dhcp_context *context,
|
|||||||
|
|
||||||
if ((p = free_space(mess, end, OPTION_CLIENT_FQDN, len)))
|
if ((p = free_space(mess, end, OPTION_CLIENT_FQDN, len)))
|
||||||
{
|
{
|
||||||
*(p++) = fqdn_flags;
|
*(p++) = fqdn_flags & 0x0f; /* MBZ bits to zero */
|
||||||
*(p++) = 255;
|
*(p++) = 255;
|
||||||
*(p++) = 255;
|
*(p++) = 255;
|
||||||
|
|
||||||
@@ -2511,8 +2355,8 @@ static void do_options(struct dhcp_context *context,
|
|||||||
|
|
||||||
/* Now send options to be encapsulated in arbitrary options,
|
/* Now send options to be encapsulated in arbitrary options,
|
||||||
eg dhcp-option=encap:172,17,.......
|
eg dhcp-option=encap:172,17,.......
|
||||||
Also hand vendor-identifying vendor-encapsulated options,
|
Also handle vendor-identifying vendor-encapsulated options,
|
||||||
dhcp-option = rfc3925-encap:13,17,.......
|
dhcp-option = vi-encap:13,17,.......
|
||||||
The may be more that one "outer" to do, so group
|
The may be more that one "outer" to do, so group
|
||||||
all the options which match each outer in turn. */
|
all the options which match each outer in turn. */
|
||||||
for (opt = config_opts; opt; opt = opt->next)
|
for (opt = config_opts; opt; opt = opt->next)
|
||||||
@@ -2579,7 +2423,7 @@ static void do_options(struct dhcp_context *context,
|
|||||||
if (context && pxe_arch != -1)
|
if (context && pxe_arch != -1)
|
||||||
{
|
{
|
||||||
pxe_misc(mess, end, uuid);
|
pxe_misc(mess, end, uuid);
|
||||||
config_opts = pxe_opts(pxe_arch, tagif, context->local);
|
config_opts = pxe_opts(pxe_arch, tagif, context->local, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((force_encap || in_list(req_options, OPTION_VENDOR_CLASS_OPT)) &&
|
if ((force_encap || in_list(req_options, OPTION_VENDOR_CLASS_OPT)) &&
|
||||||
|
|||||||
+1434
-214
File diff suppressed because it is too large.
Load diff
+207
@@ -0,0 +1,207 @@
|
|||||||
|
/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 dated June, 1991, or
|
||||||
|
(at your option) version 3 dated 29 June, 2007.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dnsmasq.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_DHCP6
|
||||||
|
|
||||||
|
#include <netinet/icmp6.h>
|
||||||
|
|
||||||
|
static int ping_id = 0;
|
||||||
|
|
||||||
|
void slaac_add_addrs(struct dhcp_lease *lease, time_t now, int force)
|
||||||
|
{
|
||||||
|
struct slaac_address *slaac, *old, **up;
|
||||||
|
struct dhcp_context *context;
|
||||||
|
int dns_dirty = 0;
|
||||||
|
|
||||||
|
if (!(lease->flags & LEASE_HAVE_HWADDR) ||
|
||||||
|
(lease->flags & (LEASE_TA | LEASE_NA)) ||
|
||||||
|
lease->last_interface == 0 ||
|
||||||
|
!lease->hostname)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
old = lease->slaac_address;
|
||||||
|
lease->slaac_address = NULL;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if ((context->flags & CONTEXT_RA_NAME) && lease->last_interface == context->if_index)
|
||||||
|
{
|
||||||
|
struct in6_addr addr = context->start6;
|
||||||
|
if (lease->hwaddr_len == 6 &&
|
||||||
|
(lease->hwaddr_type == ARPHRD_ETHER || lease->hwaddr_type == ARPHRD_IEEE802))
|
||||||
|
{
|
||||||
|
/* convert MAC address to EUI-64 */
|
||||||
|
memcpy(&addr.s6_addr[8], lease->hwaddr, 3);
|
||||||
|
memcpy(&addr.s6_addr[13], &lease->hwaddr[3], 3);
|
||||||
|
addr.s6_addr[11] = 0xff;
|
||||||
|
addr.s6_addr[12] = 0xfe;
|
||||||
|
}
|
||||||
|
#if defined(ARPHRD_EUI64)
|
||||||
|
else if (lease->hwaddr_len == 8 &&
|
||||||
|
lease->hwaddr_type == ARPHRD_EUI64)
|
||||||
|
memcpy(&addr.s6_addr[8], lease->hwaddr, 8);
|
||||||
|
#endif
|
||||||
|
#if defined(ARPHRD_IEEE1394) && defined(ARPHRD_EUI64)
|
||||||
|
else if (lease->clid_len == 9 &&
|
||||||
|
lease->clid[0] == ARPHRD_EUI64 &&
|
||||||
|
lease->hwaddr_type == ARPHRD_IEEE1394)
|
||||||
|
/* firewire has EUI-64 identifier as clid */
|
||||||
|
memcpy(&addr.s6_addr[8], &lease->clid[1], 8);
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
addr.s6_addr[8] ^= 0x02;
|
||||||
|
|
||||||
|
/* check if we already have this one */
|
||||||
|
for (up = &old, slaac = old; slaac; slaac = slaac->next)
|
||||||
|
{
|
||||||
|
if (IN6_ARE_ADDR_EQUAL(&addr, &slaac->addr))
|
||||||
|
{
|
||||||
|
*up = slaac->next;
|
||||||
|
/* recheck when DHCPv4 goes through init-reboot */
|
||||||
|
if (force)
|
||||||
|
{
|
||||||
|
slaac->ping_time = now;
|
||||||
|
slaac->backoff = 1;
|
||||||
|
dns_dirty = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
up = &slaac->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No, make new one */
|
||||||
|
if (!slaac && (slaac = whine_malloc(sizeof(struct slaac_address))))
|
||||||
|
{
|
||||||
|
slaac->ping_time = now;
|
||||||
|
slaac->backoff = 1;
|
||||||
|
slaac->addr = addr;
|
||||||
|
slaac->local = context->local6;
|
||||||
|
/* Do RA's to prod it */
|
||||||
|
ra_start_unsolicted(now, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slaac)
|
||||||
|
{
|
||||||
|
slaac->next = lease->slaac_address;
|
||||||
|
lease->slaac_address = slaac;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old || dns_dirty)
|
||||||
|
lease_update_dns(1);
|
||||||
|
|
||||||
|
/* Free any no reused */
|
||||||
|
for (; old; old = slaac)
|
||||||
|
{
|
||||||
|
slaac = old->next;
|
||||||
|
free(old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
time_t periodic_slaac(time_t now, struct dhcp_lease *leases)
|
||||||
|
{
|
||||||
|
struct dhcp_context *context;
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
struct slaac_address *slaac;
|
||||||
|
time_t next_event = 0;
|
||||||
|
|
||||||
|
for (context = daemon->dhcp6; context; context = context->next)
|
||||||
|
if ((context->flags & CONTEXT_RA_NAME))
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* nothing configured */
|
||||||
|
if (!context)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
while (ping_id == 0)
|
||||||
|
ping_id = rand16();
|
||||||
|
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
for (slaac = lease->slaac_address; slaac; slaac = slaac->next)
|
||||||
|
{
|
||||||
|
/* confirmed or given up? */
|
||||||
|
if (slaac->backoff == 0 || slaac->ping_time == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (difftime(slaac->ping_time, now) <= 0.0)
|
||||||
|
{
|
||||||
|
struct ping_packet *ping;
|
||||||
|
struct sockaddr_in6 addr;
|
||||||
|
|
||||||
|
save_counter(0);
|
||||||
|
ping = expand(sizeof(struct ping_packet));
|
||||||
|
ping->type = ICMP6_ECHO_REQUEST;
|
||||||
|
ping->code = 0;
|
||||||
|
ping->identifier = ping_id;
|
||||||
|
ping->sequence_no = slaac->backoff;
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
|
addr.sin6_len = sizeof(struct sockaddr_in6);
|
||||||
|
#endif
|
||||||
|
addr.sin6_family = AF_INET6;
|
||||||
|
addr.sin6_port = htons(IPPROTO_ICMPV6);
|
||||||
|
addr.sin6_addr = slaac->addr;
|
||||||
|
|
||||||
|
if (sendto(daemon->icmp6fd, daemon->outpacket.iov_base, save_counter(0), 0,
|
||||||
|
(struct sockaddr *)&addr, sizeof(addr)) == -1 &&
|
||||||
|
errno == EHOSTUNREACH)
|
||||||
|
slaac->ping_time = 0; /* Give up */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slaac->ping_time += (1 << (slaac->backoff - 1)) + (rand16()/21785); /* 0 - 3 */
|
||||||
|
if (slaac->backoff > 4)
|
||||||
|
slaac->ping_time += rand16()/4000; /* 0 - 15 */
|
||||||
|
if (slaac->backoff < 12)
|
||||||
|
slaac->backoff++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slaac->ping_time != 0 &&
|
||||||
|
(next_event == 0 || difftime(next_event, slaac->ping_time) >= 0.0))
|
||||||
|
next_event = slaac->ping_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
return next_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void slaac_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface, struct dhcp_lease *leases)
|
||||||
|
{
|
||||||
|
struct dhcp_lease *lease;
|
||||||
|
struct slaac_address *slaac;
|
||||||
|
struct ping_packet *ping = (struct ping_packet *)packet;
|
||||||
|
int gotone = 0;
|
||||||
|
|
||||||
|
if (ping->identifier == ping_id)
|
||||||
|
for (lease = leases; lease; lease = lease->next)
|
||||||
|
for (slaac = lease->slaac_address; slaac; slaac = slaac->next)
|
||||||
|
if (slaac->backoff != 0 && IN6_ARE_ADDR_EQUAL(sender, &slaac->addr))
|
||||||
|
{
|
||||||
|
slaac->backoff = 0;
|
||||||
|
gotone = 1;
|
||||||
|
inet_ntop(AF_INET6, sender, daemon->addrbuff, ADDRSTRLEN);
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, "SLAAC-CONFIRM(%s) %s %s", interface, daemon->addrbuff, lease->hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
lease_update_dns(gotone);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
+107
-74
@@ -18,12 +18,13 @@
|
|||||||
|
|
||||||
#ifdef HAVE_TFTP
|
#ifdef HAVE_TFTP
|
||||||
|
|
||||||
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix, int special);
|
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix);
|
||||||
static void free_transfer(struct tftp_transfer *transfer);
|
static void free_transfer(struct tftp_transfer *transfer);
|
||||||
static ssize_t tftp_err(int err, char *packet, char *mess, char *file);
|
static ssize_t tftp_err(int err, char *packet, char *mess, char *file);
|
||||||
static ssize_t tftp_err_oops(char *packet, char *file);
|
static ssize_t tftp_err_oops(char *packet, char *file);
|
||||||
static ssize_t get_block(char *packet, struct tftp_transfer *transfer);
|
static ssize_t get_block(char *packet, struct tftp_transfer *transfer);
|
||||||
static char *next(char **p, char *end);
|
static char *next(char **p, char *end);
|
||||||
|
static void sanitise(char *buf);
|
||||||
|
|
||||||
#define OP_RRQ 1
|
#define OP_RRQ 1
|
||||||
#define OP_WRQ 2
|
#define OP_WRQ 2
|
||||||
@@ -47,7 +48,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int is_err = 1, if_index = 0, mtu = 0, special = 0;
|
int is_err = 1, if_index = 0, mtu = 0;
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
struct iname *tmp;
|
struct iname *tmp;
|
||||||
#endif
|
#endif
|
||||||
@@ -57,10 +58,9 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
int mtuflag = IP_PMTUDISC_DONT;
|
int mtuflag = IP_PMTUDISC_DONT;
|
||||||
#endif
|
#endif
|
||||||
char namebuff[IF_NAMESIZE];
|
char namebuff[IF_NAMESIZE];
|
||||||
char *name;
|
char *name = NULL;
|
||||||
char *prefix = daemon->tftp_prefix;
|
char *prefix = daemon->tftp_prefix;
|
||||||
struct tftp_prefix *pref;
|
struct tftp_prefix *pref;
|
||||||
struct interface_list *ir;
|
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct cmsghdr align; /* this ensures alignment */
|
struct cmsghdr align; /* this ensures alignment */
|
||||||
@@ -95,15 +95,24 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
|
|
||||||
if (option_bool(OPT_NOWILD))
|
if (option_bool(OPT_NOWILD))
|
||||||
{
|
{
|
||||||
addr = listen->iface->addr;
|
if (listen->iface)
|
||||||
mtu = listen->iface->mtu;
|
{
|
||||||
name = listen->iface->name;
|
addr = listen->iface->addr;
|
||||||
|
mtu = listen->iface->mtu;
|
||||||
|
name = listen->iface->name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* we're listening on an address that doesn't appear on an interface,
|
||||||
|
ask the kernel what the socket is bound to */
|
||||||
|
socklen_t tcp_len = sizeof(union mysockaddr);
|
||||||
|
if (getsockname(listen->tftpfd, (struct sockaddr *)&addr, &tcp_len) == -1)
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct cmsghdr *cmptr;
|
struct cmsghdr *cmptr;
|
||||||
int check;
|
|
||||||
struct interface_list *ir;
|
|
||||||
|
|
||||||
if (msg.msg_controllen < sizeof(struct cmsghdr))
|
if (msg.msg_controllen < sizeof(struct cmsghdr))
|
||||||
return;
|
return;
|
||||||
@@ -183,43 +192,34 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if (listen->family == AF_INET6)
|
if (listen->family == AF_INET6)
|
||||||
check = iface_check(AF_INET6, (struct all_addr *)&addr.in6.sin6_addr, name);
|
{
|
||||||
|
if (!iface_check(AF_INET6, (struct all_addr *)&addr.in6.sin6_addr, name, NULL))
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
check = iface_check(AF_INET, (struct all_addr *)&addr.in.sin_addr, name);
|
if (!iface_check(AF_INET, (struct all_addr *)&addr.in.sin_addr, name, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
/* wierd TFTP service override */
|
|
||||||
for (ir = daemon->tftp_interfaces; ir; ir = ir->next)
|
|
||||||
if (strcmp(ir->interface, name) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!ir)
|
|
||||||
{
|
|
||||||
if (!daemon->tftp_unlimited || !check)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
/* allowed interfaces are the same as for DHCP */
|
/* allowed interfaces are the same as for DHCP */
|
||||||
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
|
||||||
if (tmp->name && (strcmp(tmp->name, name) == 0))
|
if (tmp->name && (strcmp(tmp->name, name) == 0))
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, name, IF_NAMESIZE);
|
strncpy(ifr.ifr_name, name, IF_NAMESIZE);
|
||||||
if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
|
if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
|
||||||
mtu = ifr.ifr_mtu;
|
mtu = ifr.ifr_mtu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for per-interface prefix */
|
if (name)
|
||||||
for (pref = daemon->if_prefix; pref; pref = pref->next)
|
{
|
||||||
if (strcmp(pref->interface, name) == 0)
|
/* check for per-interface prefix */
|
||||||
prefix = pref->prefix;
|
for (pref = daemon->if_prefix; pref; pref = pref->next)
|
||||||
|
if (strcmp(pref->interface, name) == 0)
|
||||||
/* wierd TFTP interfaces disable special options. */
|
prefix = pref->prefix;
|
||||||
for (ir = daemon->tftp_interfaces; ir; ir = ir->next)
|
}
|
||||||
if (strcmp(ir->interface, name) == 0)
|
|
||||||
special = 1;
|
|
||||||
|
|
||||||
if (listen->family == AF_INET)
|
if (listen->family == AF_INET)
|
||||||
{
|
{
|
||||||
@@ -297,7 +297,10 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
!(filename = next(&p, end)) ||
|
!(filename = next(&p, end)) ||
|
||||||
!(mode = next(&p, end)) ||
|
!(mode = next(&p, end)) ||
|
||||||
(strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0))
|
(strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0))
|
||||||
len = tftp_err(ERR_ILL, packet, _("unsupported request from %s"), daemon->addrbuff);
|
{
|
||||||
|
len = tftp_err(ERR_ILL, packet, _("unsupported request from %s"), daemon->addrbuff);
|
||||||
|
is_err = 1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (strcasecmp(mode, "netascii") == 0)
|
if (strcasecmp(mode, "netascii") == 0)
|
||||||
@@ -307,8 +310,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
{
|
{
|
||||||
if (strcasecmp(opt, "blksize") == 0)
|
if (strcasecmp(opt, "blksize") == 0)
|
||||||
{
|
{
|
||||||
if ((opt = next(&p, end)) &&
|
if ((opt = next(&p, end)) && !option_bool(OPT_TFTP_NOBLOCK))
|
||||||
(special || !option_bool(OPT_TFTP_NOBLOCK)))
|
|
||||||
{
|
{
|
||||||
transfer->blocksize = atoi(opt);
|
transfer->blocksize = atoi(opt);
|
||||||
if (transfer->blocksize < 1)
|
if (transfer->blocksize < 1)
|
||||||
@@ -330,9 +332,12 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* cope with backslashes from windows boxen. */
|
/* cope with backslashes from windows boxen. */
|
||||||
while ((p = strchr(filename, '\\')))
|
for (p = filename; *p; p++)
|
||||||
*p = '/';
|
if (*p == '\\')
|
||||||
|
*p = '/';
|
||||||
|
else if (option_bool(OPT_TFTP_LC))
|
||||||
|
*p = tolower(*p);
|
||||||
|
|
||||||
strcpy(daemon->namebuff, "/");
|
strcpy(daemon->namebuff, "/");
|
||||||
if (prefix)
|
if (prefix)
|
||||||
{
|
{
|
||||||
@@ -342,7 +347,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
if (prefix[strlen(prefix)-1] != '/')
|
if (prefix[strlen(prefix)-1] != '/')
|
||||||
strncat(daemon->namebuff, "/", (MAXDNAME-1) - strlen(daemon->namebuff));
|
strncat(daemon->namebuff, "/", (MAXDNAME-1) - strlen(daemon->namebuff));
|
||||||
|
|
||||||
if (!special && option_bool(OPT_TFTP_APREF))
|
if (option_bool(OPT_TFTP_APREF))
|
||||||
{
|
{
|
||||||
size_t oldlen = strlen(daemon->namebuff);
|
size_t oldlen = strlen(daemon->namebuff);
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
@@ -369,7 +374,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
strncat(daemon->namebuff, filename, (MAXDNAME-1) - strlen(daemon->namebuff));
|
strncat(daemon->namebuff, filename, (MAXDNAME-1) - strlen(daemon->namebuff));
|
||||||
|
|
||||||
/* check permissions and open file */
|
/* check permissions and open file */
|
||||||
if ((transfer->file = check_tftp_fileperm(&len, prefix, special)))
|
if ((transfer->file = check_tftp_fileperm(&len, prefix)))
|
||||||
{
|
{
|
||||||
if ((len = get_block(packet, transfer)) == -1)
|
if ((len = get_block(packet, transfer)) == -1)
|
||||||
len = tftp_err_oops(packet, daemon->namebuff);
|
len = tftp_err_oops(packet, daemon->namebuff);
|
||||||
@@ -379,7 +384,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (sendto(transfer->sockfd, packet, len, 0,
|
while (sendto(transfer->sockfd, packet, len, 0,
|
||||||
(struct sockaddr *)&peer, sizeof(peer)) == -1 && errno == EINTR);
|
(struct sockaddr *)&peer, sa_len(&peer)) == -1 && errno == EINTR);
|
||||||
|
|
||||||
if (is_err)
|
if (is_err)
|
||||||
free_transfer(transfer);
|
free_transfer(transfer);
|
||||||
@@ -390,7 +395,7 @@ void tftp_request(struct listener *listen, time_t now)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix, int special)
|
static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix)
|
||||||
{
|
{
|
||||||
char *packet = daemon->packet, *namebuff = daemon->namebuff;
|
char *packet = daemon->packet, *namebuff = daemon->namebuff;
|
||||||
struct tftp_file *file;
|
struct tftp_file *file;
|
||||||
@@ -427,7 +432,7 @@ static struct tftp_file *check_tftp_fileperm(ssize_t *len, char *prefix, int spe
|
|||||||
goto perm;
|
goto perm;
|
||||||
}
|
}
|
||||||
/* in secure mode, must be owned by user running dnsmasq */
|
/* in secure mode, must be owned by user running dnsmasq */
|
||||||
else if (!special && option_bool(OPT_TFTP_SECURE) && uid != statbuf.st_uid)
|
else if (option_bool(OPT_TFTP_SECURE) && uid != statbuf.st_uid)
|
||||||
goto perm;
|
goto perm;
|
||||||
|
|
||||||
/* If we're doing many tranfers from the same file, only
|
/* If we're doing many tranfers from the same file, only
|
||||||
@@ -487,12 +492,12 @@ void check_tftp_listeners(fd_set *rset, time_t now)
|
|||||||
{
|
{
|
||||||
tmp = transfer->next;
|
tmp = transfer->next;
|
||||||
|
|
||||||
|
prettyprint_addr(&transfer->peer, daemon->addrbuff);
|
||||||
|
|
||||||
if (FD_ISSET(transfer->sockfd, rset))
|
if (FD_ISSET(transfer->sockfd, rset))
|
||||||
{
|
{
|
||||||
/* we overwrote the buffer... */
|
/* we overwrote the buffer... */
|
||||||
daemon->srv_save = NULL;
|
daemon->srv_save = NULL;
|
||||||
|
|
||||||
prettyprint_addr(&transfer->peer, daemon->addrbuff);
|
|
||||||
|
|
||||||
if ((len = recv(transfer->sockfd, daemon->packet, daemon->packet_buff_sz, 0)) >= (ssize_t)sizeof(struct ack))
|
if ((len = recv(transfer->sockfd, daemon->packet, daemon->packet_buff_sz, 0)) >= (ssize_t)sizeof(struct ack))
|
||||||
{
|
{
|
||||||
@@ -514,14 +519,8 @@ void check_tftp_listeners(fd_set *rset, time_t now)
|
|||||||
if (!err)
|
if (!err)
|
||||||
err = "";
|
err = "";
|
||||||
else
|
else
|
||||||
{
|
sanitise(err);
|
||||||
unsigned char *q, *r;
|
|
||||||
for (q = r = (unsigned char *)err; *r; r++)
|
|
||||||
if (isprint(*r))
|
|
||||||
*(q++) = *r;
|
|
||||||
*q = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my_syslog(MS_TFTP | LOG_ERR, _("error %d %s received from %s"),
|
my_syslog(MS_TFTP | LOG_ERR, _("error %d %s received from %s"),
|
||||||
(int)ntohs(mess->block), err,
|
(int)ntohs(mess->block), err,
|
||||||
daemon->addrbuff);
|
daemon->addrbuff);
|
||||||
@@ -548,30 +547,33 @@ void check_tftp_listeners(fd_set *rset, time_t now)
|
|||||||
len = tftp_err_oops(daemon->packet, transfer->file->filename);
|
len = tftp_err_oops(daemon->packet, transfer->file->filename);
|
||||||
endcon = 1;
|
endcon = 1;
|
||||||
}
|
}
|
||||||
else if (++transfer->backoff > 5)
|
/* don't complain about timeout when we're awaiting the last
|
||||||
|
ACK, some clients never send it */
|
||||||
|
else if (++transfer->backoff > 5 && len != 0)
|
||||||
{
|
{
|
||||||
/* don't complain about timeout when we're awaiting the last
|
endcon = 1;
|
||||||
ACK, some clients never send it */
|
len = 0;
|
||||||
if (len != 0)
|
|
||||||
{
|
|
||||||
my_syslog(MS_TFTP | LOG_ERR, _("failed sending %s to %s"),
|
|
||||||
transfer->file->filename, daemon->addrbuff);
|
|
||||||
len = 0;
|
|
||||||
endcon = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != 0)
|
if (len != 0)
|
||||||
while(sendto(transfer->sockfd, daemon->packet, len, 0,
|
while(sendto(transfer->sockfd, daemon->packet, len, 0,
|
||||||
(struct sockaddr *)&transfer->peer, sizeof(transfer->peer)) == -1 && errno == EINTR);
|
(struct sockaddr *)&transfer->peer, sa_len(&transfer->peer)) == -1 && errno == EINTR);
|
||||||
|
|
||||||
if (endcon || len == 0)
|
if (endcon || len == 0)
|
||||||
{
|
{
|
||||||
if (!endcon)
|
strcpy(daemon->namebuff, transfer->file->filename);
|
||||||
my_syslog(MS_TFTP | LOG_INFO, _("sent %s to %s"), transfer->file->filename, daemon->addrbuff);
|
sanitise(daemon->namebuff);
|
||||||
|
my_syslog(MS_TFTP | LOG_INFO, endcon ? _("failed sending %s to %s") : _("sent %s to %s"), daemon->namebuff, daemon->addrbuff);
|
||||||
/* unlink */
|
/* unlink */
|
||||||
*up = tmp;
|
*up = tmp;
|
||||||
free_transfer(transfer);
|
if (endcon)
|
||||||
|
free_transfer(transfer);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* put on queue to be sent to script and deleted */
|
||||||
|
transfer->next = daemon->tftp_done_trans;
|
||||||
|
daemon->tftp_done_trans = transfer;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,6 +607,16 @@ static char *next(char **p, char *end)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sanitise(char *buf)
|
||||||
|
{
|
||||||
|
unsigned char *q, *r;
|
||||||
|
for (q = r = (unsigned char *)buf; *r; r++)
|
||||||
|
if (isprint((int)*r))
|
||||||
|
*(q++) = *r;
|
||||||
|
*q = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t tftp_err(int err, char *packet, char *message, char *file)
|
static ssize_t tftp_err(int err, char *packet, char *message, char *file)
|
||||||
{
|
{
|
||||||
struct errmess {
|
struct errmess {
|
||||||
@@ -613,7 +625,9 @@ static ssize_t tftp_err(int err, char *packet, char *message, char *file)
|
|||||||
} *mess = (struct errmess *)packet;
|
} *mess = (struct errmess *)packet;
|
||||||
ssize_t ret = 4;
|
ssize_t ret = 4;
|
||||||
char *errstr = strerror(errno);
|
char *errstr = strerror(errno);
|
||||||
|
|
||||||
|
sanitise(file);
|
||||||
|
|
||||||
mess->op = htons(OP_ERR);
|
mess->op = htons(OP_ERR);
|
||||||
mess->err = htons(err);
|
mess->err = htons(err);
|
||||||
ret += (snprintf(mess->message, 500, message, file, errstr) + 1);
|
ret += (snprintf(mess->message, 500, message, file, errstr) + 1);
|
||||||
@@ -624,7 +638,9 @@ static ssize_t tftp_err(int err, char *packet, char *message, char *file)
|
|||||||
|
|
||||||
static ssize_t tftp_err_oops(char *packet, char *file)
|
static ssize_t tftp_err_oops(char *packet, char *file)
|
||||||
{
|
{
|
||||||
return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), file);
|
/* May have >1 refs to file, so potentially mangle a copy of the name */
|
||||||
|
strcpy(daemon->namebuff, file);
|
||||||
|
return tftp_err(ERR_NOTDEF, packet, _("cannot read %s: %s"), daemon->namebuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return -1 for error, zero for done. */
|
/* return -1 for error, zero for done. */
|
||||||
@@ -709,4 +725,21 @@ static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int do_tftp_script_run(void)
|
||||||
|
{
|
||||||
|
struct tftp_transfer *transfer;
|
||||||
|
|
||||||
|
if ((transfer = daemon->tftp_done_trans))
|
||||||
|
{
|
||||||
|
daemon->tftp_done_trans = transfer->next;
|
||||||
|
#ifdef HAVE_SCRIPT
|
||||||
|
queue_tftp(transfer->file->size, transfer->file->filename, &transfer->peer);
|
||||||
|
#endif
|
||||||
|
free_transfer(transfer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
+47
-7
@@ -280,7 +280,7 @@ int sa_len(union mysockaddr *addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* don't use strcasecmp and friends here - they may be messed up by LOCALE */
|
/* don't use strcasecmp and friends here - they may be messed up by LOCALE */
|
||||||
int hostname_isequal(char *a, char *b)
|
int hostname_isequal(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
unsigned int c1, c2;
|
unsigned int c1, c2;
|
||||||
|
|
||||||
@@ -330,12 +330,35 @@ int is_same_net6(struct in6_addr *a, struct in6_addr *b, int prefixlen)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (pfbits == 0 ||
|
if (pfbits == 0 ||
|
||||||
(a->s6_addr[pfbytes] >> (8 - pfbits) != b->s6_addr[pfbytes] >> (8 - pfbits)))
|
(a->s6_addr[pfbytes] >> (8 - pfbits) == b->s6_addr[pfbytes] >> (8 - pfbits)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return least signigicant 64 bits if IPv6 address */
|
||||||
|
u64 addr6part(struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
u64 ret = 0;
|
||||||
|
|
||||||
|
for (i = 8; i < 16; i++)
|
||||||
|
ret = (ret << 8) + addr->s6_addr[i];
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setaddr6part(struct in6_addr *addr, u64 host)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 15; i >= 8; i--)
|
||||||
|
{
|
||||||
|
addr->s6_addr[i] = host;
|
||||||
|
host = host >> 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -403,7 +426,7 @@ int parse_hex(char *in, unsigned char *out, int maxlen,
|
|||||||
|
|
||||||
while (maxlen == -1 || i < maxlen)
|
while (maxlen == -1 || i < maxlen)
|
||||||
{
|
{
|
||||||
for (r = in; *r != 0 && *r != ':' && *r != '-'; r++)
|
for (r = in; *r != 0 && *r != ':' && *r != '-' && *r != ' '; r++)
|
||||||
if (*r != '*' && !isxdigit((unsigned char)*r))
|
if (*r != '*' && !isxdigit((unsigned char)*r))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -421,12 +444,29 @@ int parse_hex(char *in, unsigned char *out, int maxlen,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
*r = 0;
|
*r = 0;
|
||||||
mask = mask << 1;
|
|
||||||
if (strcmp(in, "*") == 0)
|
if (strcmp(in, "*") == 0)
|
||||||
mask |= 1;
|
{
|
||||||
|
mask = (mask << 1) | 1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
out[i] = strtol(in, NULL, 16);
|
{
|
||||||
i++;
|
int j, bytes = (1 + (r - in))/2;
|
||||||
|
for (j = 0; j < bytes; j++)
|
||||||
|
{
|
||||||
|
char sav;
|
||||||
|
if (j < bytes - 1)
|
||||||
|
{
|
||||||
|
sav = in[(j+1)*2];
|
||||||
|
in[(j+1)*2] = 0;
|
||||||
|
}
|
||||||
|
out[i] = strtol(&in[j*2], NULL, 16);
|
||||||
|
mask = mask << 1;
|
||||||
|
i++;
|
||||||
|
if (j < bytes - 1)
|
||||||
|
in[(j+1)*2] = sav;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in = r+1;
|
in = r+1;
|
||||||
|
|||||||
Reference in new issue
Block a user