Commit 3d8df260 authored by Simon Kelley's avatar Simon Kelley

import of dnsmasq-2.23.tar.gz

parent 91dccd09
......@@ -1444,3 +1444,103 @@ version 2.22
regression. Rob Holland and Roy Marples chased this one
down.
version 2.23
Added a check to ensure that there cannot be more than one
dhcp-host option for any one IP address, even if the
addresses are assigned indirectly via a hostname and
/etc/hosts.
Include a "server identifier" in DHCPNAK replies, as
required by RFC2131.
Added method support for DBus
(http://www.freedesktop.org/Software/dbus)
This is a superior way to re-configure dnsmasq on-the-fly
with different upstream nameservers, as the host moves
between networks. DBus support must be enabled in
src/config.h and should be considered experimental at this
point. See DBus-interface for the specification of the
DBus method calls supported.
Added information to the FAQ about setting the DNS domain
in windows XP and Mac OS X, thanks to Rick Hull.
Added sanity check to resolv.conf polling code to cope
with backwards-moving clocks. Thanks to Leonardo Canducci
for help with this.
Handle so-called "A-for-A" queries, which are queries for
the address associated with a name which is already a
dotted-quad address. These should be handled by the
resolver code, but sometimes aren't and there's no point
in forwarding them.
Added "no-dhcp-interface" option to disable DHCP service
on an interface, whilst still providing DNS.
Fix format-string problem - config file names get passed
to fprintf as a format string, so % characters could cause
crashes. Thanks to Rob Holland for sleuthing that one.
Fixed multiple compiler warnings from gcc 4. Thanks to
Tim Cutts for the report.
Send the hostname option on DHCP offer messages as well as
DHCP ack messages. This is required by the Rio Digital
Audio Receiver. Thanks to Ron Frederick for the patch.
Add 'd' (for day) as a possible time multiplier in lease
time specifications. Thanks to Michael Deegan.
Make quoting suppress recognition of IP addresses, so
dhcp-option=66,1.2.3.4 now means something different to
dhcp-option=66,"1.2.3.4", which sets the option to a
string value. Thanks to Brian Macauley for the bug report.
Fixed the option parsing code to avoid segfaults from some
invalid configurations. Thanks to Wookey for spotting that one.
Provide information about which compile-time options were
selected, both in the log at startup and as part of the output
from dnsmasq --version. Thanks to Dirk Schenkewitz for
the suggestion.
Fix pathalogical behaviour when a broken client keeps sending
DHCPDISCOVER messages repeatedly and fast. Because dealing with
each of these takes a few seconds, (because of the ping) then a
queue of DHCP packets could build up. Now, the results of a ping
test are assumed to be valid for 30 seconds, so repeated waits are
not required. Thanks to Luca Landi for finding this.
Allow DHCPINFORM requests without hardware address
information. These are generated by some browsers, looking
for proxy information. Thanks to Stanley Jaddoe for the
bug report on that.
Add support of the "client FQDN" DHCP option. If present,
this is used to allow the client to tell dnsmasq its name,
in preference to (mis)using the hostname option. See
http://tools.ietf.org/wg/dhc/draft-ietf-dhc-fqdn-option/\
draft-ietf-dhc-fqdn-option-10.txt
for details of the draft spec.
Added startup scripts for MacOS X Tiger/Panther to the
contrib collection. Thanks to Tim Cutts.
Tweak DHCP network selection so that clients which turn up
on our network in REBINDING state and with a lease for a
foreign network will get a NAK response. Thanks to Dan
Shechter for work on this and an initial patch and thanks
to Gyorgy Farkas for further testing.
Fix DNS query forwarding for empty queries and forward
queries even when the recursion-desired bit is clear. This
allows "dig +trace" to work. Problem report from Uwe
Gansert.
Added "const" declarations where appropriate, thanks to
Andreas Mohr for the patch.
Added --bootp-dynamic option and associated
functionality. Thanks to Josef Wolf for the suggestion.
DBus support must be enabled at compile-time and run-time. Ensure
that src/config.h contains the line
#define HAVE_DBUS.
and that /etc/dnsmasq.conf contains the line
enable-dbus
Because dnsmasq can operate stand-alone from the DBus, and may need to provide
service before the dbus daemon is available, it will continue to run
if the DBus connection is not available at startup. The DBus will be polled
every 250ms until a connection is established. Start of polling and final
connection establishment are both logged. When dnsmasq establishes a
connection to the dbus, it sends the signal "Up". Anything controlling
the server settings in dnsmasq should re-invoke the SetServers method
(q.v.) when it sees this signal. This allows dnsmasq to be restarted
and avoids startup races with the provider of nameserver information.
Dnsmasq provides one service on the DBus: uk.org.thekelleys.dnsmasq
and a single object: /uk/org/thekelleys/dnsmasq
Methods are of the form
uk.org.thekelleys.<method>
Available methods are:
GetVersion
----------
Returns a string containing the version of dnsmasq running.
ClearCache
----------
Returns nothing. Clears the domain name cache and re-reads
/etc/hosts. The same as sending dnsmasq a HUP signal.
SetServers
----------
Returns nothing. Takes a set of arguments representing the new
upstream DNS servers to be used by dnsmasq. IPv4 addresses are
represented as a UINT32 (in network byte order) and IPv6 addresses
are represented as sixteen BYTEs (since there is no UINT128 type).
Each server address may be followed by one or more STRINGS, which are
the domains for which the preceding server should be used.
Examples.
UINT32: <address1>
UNIT32: <address2>
is equivalent to
--server=<address1> --server=<address2>
UINT32 <address1>
UINT32 <address2>
STRING "somedomain.com"
is equivalent to
--server=<address1> --server=/somedomain.com/<address2>
UINT32 <address1>
UINT32 <address2>
STRING "somedomain.com"
UINT32 <address3>
STRING "anotherdomain.com"
STRING "thirddomain.com"
is equivalent to
--server=<address1>
--server=/somedomain.com/<address2>
--server=/anotherdomain.com/thirddomain.com/<address3>
Am IPv4 address of 0.0.0.0 is interpreted as "no address, local only",
so
UINT32: <0.0.0.0>
STRING "local.domain"
is equivalent to
--local=/local.domain/
Each call to SetServers 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.
......@@ -39,18 +39,15 @@ A: They are negative entries: that's what the N flag means. Dnsmasq asked
Q: Will dnsmasq compile/run on non-Linux systems?
A: Yes, there is explicit support for *BSD and Solaris.
A: Yes, there is explicit support for *BSD and MacOS X. There are
start-up scripts for MacOS X Tiger and Panther in /contrib. Earlier
dnsmasq releases ran under Solaris, but that capability has
probably rotted. Dnsmasq will link with uclibc to provide small
binaries suitable for use in embedded systems such as
routers. (There's special code to support machines with flash
filesystems and no battery-backed RTC.)
For other systems, try altering the settings in config.h.
A: Update for V2. Doing DHCP is rather non-portable, so there may be
a few teething troubles. The initial 2.0 release is known to work
on Linux 2.2.x, Linux 2.4.x and Linux 2.6.x with uclibc and glibc
2.3. It also works on FreeBSD 4.8. The crucial problem is sending
raw packets, bypassing the IP stack. Dnsmasq contains code to do
using PF_PACKET sockets (which is for Linux) and the Berkeley packet
filter (which works with BSD). If you are trying to port to another
Un*x, bpf is the most likeley candidate. See config.h
Q: My companies' nameserver knows about some names which aren't in the
public DNS. Even though I put it first in /etc/resolv.conf, it
dosen't work: dnsmasq seems not to use the nameservers in the order
......@@ -88,7 +85,7 @@ A: This has been seen when a system is bringing up a PPP interface at
Q: I'm running on BSD and dnsmasq won't accept long options on the
command line.
A: Dnsmasq when built on BSD systems doesn't use GNU getopt by
A: Dnsmasq when built on some BSD systems doesn't use GNU getopt by
default. You can either just use the single-letter options or
change config.h and the Makefile to use getopt-long. Note that
options in /etc/dnsmasq.conf must always be the long form,
......@@ -105,13 +102,23 @@ A: Resolver code sometime does strange things when given names without
"ping" will get a lookup failure, appending a dot to the end of the
hostname will fix things. (ie "ping myhost" fails, but "ping
myhost." works. The solution is to make sure that all your hosts
have a domain set ("domain" in resolv.conf, the network applet in
windows, or set a domain in your DHCP server). Any domain will do,
but "localnet" is traditional. Now when you resolve "myhost" the
resolver will attempt to look up "myhost.localnet" so you need to
have dnsmasq reply to that name. The way to do that is to include
the domain in each name on /etc/hosts and/or to use the
--expand-hosts and --domain options.
have a domain set ("domain" in resolv.conf, or set a domain in
your DHCP server, see below fr Windows XP and Mac OS X).
Any domain will do, but "localnet" is traditional. Now when you
resolve "myhost" the resolver will attempt to look up
"myhost.localnet" so you need to have dnsmasq reply to that name.
The way to do that is to include the domain in each name on
/etc/hosts and/or to use the --expand-hosts and --domain options.
Q: How do I set the DNS domain in Windows XP or MacOS X (ref: previous
question)?
A: for XP, Control Panel > Network Connections > { Connection to gateway /
DNS } > Properties > { Highlight TCP/IP } > Properties > Advanced >
DNS Tab > DNS suffix for this connection:
A: for OS X, System Preferences > Network > {Connection to gateway / DNS } >
Search domains:
Q: Can I get dnsmasq to save the contents of its cache to disk when
I shut my machine down and re-load when it starts again?
......@@ -281,7 +288,9 @@ Q: Can I get email notification when a new version of dnsmasq is
A: Yes, new releases of dnsmasq are always announced through
freshmeat.net, and they allow you to subcribe to email alerts when
new versions of particular projects are released.
new versions of particular projects are released. New releases are
also announced in the dnsmasq-discuss mailing list, subscribe at
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Q: What does the dhcp-authoritative option do?
......@@ -301,7 +310,7 @@ A: Because when a Gentoo box shuts down, it releases its lease with
Q: My laptop has two network interfaces, a wired one and a wireless
one. I never use both interfaces at the same time, and I'd like the
same IP and configuration to be used irrespcetive of which
interface is in use. How can I do that.
interface is in use. How can I do that?
A: By default, the identity of a machine is determined by using the
MAC address, which is associated with interface hardware. Once an
......@@ -320,12 +329,11 @@ Q: Can dnsmasq do DHCP on IP-alias interfaces?
A: Yes, from version-2.21. The support is only available running under
Linux, on a kernel which provides the RT-netlink facility. All 2.4
and 2.6 kernels provide RT-netlink and it's an option in 2.2
kernels. If dnsmasq is built under uclibc, even on Linux, then
the support is not included.
kernels.
If a physical interface has more than one IP address or aliases
with extra IP addresses, then any dhcp-ranges corresponding to
these addresses can be used for address allocation. So is and
these addresses can be used for address allocation. So if an
interface has addresses 192.168.1.0/24 and 192.68.2.0/24 and there
are DHCP ranges 192.168.1.100-192.168.1.200 and
192.168.2.100-192.168.2.200 then both ranges would be used for host
......@@ -334,6 +342,21 @@ A: Yes, from version-2.21. The support is only available running under
hosts allocated addresses on that subnet using dhcp-host options,
while anonymous hosts go on the other.
Q: Dnsmasq sometimes logs "nameserver xxx.xxx.xxx.xxx refused
to do a recursive query" and DNS stops working. What's going on?
A: Probably the nameserver is an authoritative nameserver for a
particular domain, but is not configured to answer general DNS
queries for an arbitrary domain. It is not suitable for use by
dnsmasq as an upstream server and should be removed from the
configuration. Note that if you have more than one upstream
nameserver configured dnsmasq will load-balance across them and
it may be some time before dnsmasq gets around to using a
particular nameserver. This means that a particular configuration
may work for sometime with a broken upstream nameserver
configuration.
......
......@@ -7,10 +7,10 @@ SRC = src
CFLAGS?= -O2
all :
@cd $(SRC); $(MAKE) dnsmasq
$(MAKE) -f ../bld/Makefile -C $(SRC) dnsmasq
clean :
rm -f *~ contrib/*/*~ */*~ $(SRC)/*.o $(SRC)/dnsmasq core build
rm -f *~ bld/*~ contrib/*/*~ */*~ $(SRC)/*.o $(SRC)/dnsmasq core build
install : all
install -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
......
# Uncomment this on Solaris.
#LIBS = -lsocket -lnsl
CFLAGS ?= -O2
PKG_CONFIG ?= pkg-config
OBJS = cache.o rfc1035.o util.o option.o forward.o isc.o network.o \
dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o
.c.o: dnsmasq.h config.h
$(CC) $(CFLAGS) `../bld/pkg-wrapper $(PKG_CONFIG) --cflags dbus-1` $(RPM_OPT_FLAGS) -Wall -W -c $*.c
dnsmasq : $(OBJS) dnsmasq.h config.h
$(CC) -o $@ $(OBJS) `../bld/pkg-wrapper $(PKG_CONFIG) --libs dbus-1` $(LIBS)
#!/bin/sh
if grep -q "^\#.*define.*HAVE_DBUS" config.h ; then
exec $*
fi
#!/bin/sh
. /etc/rc.common
StartService() {
if [ "${DNSMASQ:=-NO-}" = "-YES-" ] ; then
/usr/local/sbin/dnsmasq -q -n
fi
}
StopService() {
pid=`GetPID dnsmasq`
if [ $? -eq 0 ]; then
kill $pid
fi
}
RestartService() {
StopService "$@"
StartService "$@"
}
RunService "$1"
{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf100
{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fnil\fcharset77 Monaco;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww11120\viewh10100\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
\f0\fs24 \cf0 1. If you've used DNSenabler, or if you're using Mac OS X Server, or if you have in any other way activated Mac OS X's built-in DHCP and/or DNS servers, disable them. This would usually involve checking that they are either set to -NO- or absent altogether in
\f1 /etc/hostconfig
\f0 . If you've never done anything to do with DNS or DHCP servers on a client version of MacOS X, you won't need to worry about this; it will already be configured for you.\
\
2. Add a configuration item to
\f1 /etc/hostconfig
\f0 as follows:\
\
\f1 DNSMASQ=-YES-
\f0 \
\
3. Create a system-wide StartupItems directory for dnsmasq:\
\
\f1 sudo mkdir -p /Library/StartupItems/DNSmasq\
\f0 \
4. Copy the files
\f1 DNSmasq
\f0 and
\f1 StartupParameters.plist
\f0 into this directory, and make sure the former is executable:\
\
\f1 sudo cp DNSmasq StartupParameters.plist /Library/StartupItems/DNSmasq\
sudo chmod 755 /Library/StartupItems/DNSmasq/DNSmasq\
\f0 \
5. Start the service:\
\
\f1 sudo /Library/StartupItems/DNSmasq/DNSmasq start\
\f0 \cf0 \
That should be all...}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>DNSmasq</string>
<key>OrderPreference</key>
<string>None</string>
<key>Provides</key>
<array>
<string>DNSmasq</string>
</array>
<key>Uses</key>
<array>
<string>Network</string>
</array>
</dict>
</plist>
The patch I have attached lets me get the behavior I wish out of
dnsmasq. I also include my version of dhclient-enter-hooks as
required for the switchover from pre-dnsmasq and dhclient.
On 8/16/05, Joseph Tate <dragonstrider@gmail.com> wrote:
> I'm trying to use dnsmasq on a laptop in order to facilitate openvpn
> connections. As such, the only configuration option I'm concerned
> about is a single server=3D/example.com/192.168.0.1 line.
>
> The way I currently have it set up is I modified dhclient to write its
> resolv.conf data to /etc/resolv.conf.dhclient and configured
> /etc/dnsmasq.conf to look there for its upstream dns servers.
> /etc/resolv.conf is set to nameserver 127.0.0.1
>
> All of this works great. When I start the openvpn service, it the
> routes, and queries to the domain in the server=3D line work just fine.
>
> The only problem is that the hostname for my system doesn't get set
> correctly. With the resolv.conf data written to something other than
> /etc/resolv.conf, the ifup scripts don't have a valid dns server to do
> the ipcalc call to set the laptop's hostname. If I start dnsmasq
> before the network comes up, something gets fubar'd. I'm not sure how
> to describe it exactly, but network services are slow to load, and
> restarting networking and dnsmasq doesn't solve the problem. Perhaps
> dnsmasq is answering the dhcp request when the network starts?
> Certainly not desired behavior.
>
> Anyway, my question: is there a way to have the best of both worlds?
> DHCP requests to another server, and DNS lookups that work at all
> times?
>
> My current best idea on how to solve this problem is modifying the
> dnsmasq initscript to tweak /etc/dhclient-enter-hooks to change where
> dhclient writes resolv.conf data, and fixing up /etc/resolv.conf on
> the fly to set 127.0.0.1 to the nameserver (and somehow keep the
> search domains intact), but I'm hoping that I'm just missing some key
> piece of the puzzle and that this problem has been solved before. Any
> insights?
>
> --
> Joseph Tate
> Personal e-mail: jtate AT dragonstrider DOT com
> Web: http://www.dragonstrider.com
>
#!/bin/bash
function save_previous() {
if [ -e $1 -a ! -e $1.predhclient ]; then
mv $1 $1.predhclient
fi
}
function write_resolv_conf() {
RESOLVCONF=$1
if [ -n "$new_domain_name" ] || [ -n "$new_domain_name_servers" ]; then
save_previous $RESOLVCONF
echo '; generated by /etc/dhclient-enter-hooks' > $RESOLVCONF
if [ -n "$SEARCH" ]; then
echo search $SEARCH >> $RESOLVCONF
else
if [ -n "$new_domain_name" ]; then
echo search $new_domain_name >> $RESOLVCONF
fi
fi
chmod 644 $RESOLVCONF
for nameserver in $new_domain_name_servers; do
echo nameserver $nameserver >>$RESOLVCONF
done
fi
}
make_resolv_conf() {
write_resolv_conf /etc/resolv.conf
}
--- dnsmasq-2.22/rpm/dnsmasq.rh 2005-03-24 09:51:18.000000000 -0500
+++ dnsmasq-2.22/rpm/dnsmasq.rh.new 2005-08-25 10:52:04.310568784 -0400
@@ -2,7 +2,7 @@
#
# Startup script for the DNS caching server
#
-# chkconfig: 2345 99 01
+# chkconfig: 2345 07 89
# description: This script starts your DNS caching server
# processname: dnsmasq
# pidfile: /var/run/dnsmasq.pid
@@ -10,6 +10,25 @@
# Source function library.
. /etc/rc.d/init.d/functions
+function setup_dhclient_enter_hooks() {
+ if [ -f /etc/dhclient-enter-hooks ]; then
+ . /etc/dhclient-enter-hooks
+ cp /etc/resolv.conf /etc/resolv.conf.dnsmasq
+ cp /etc/dhclient-enter-hooks /etc/dhclient-enter-hooks.dnsmasq
+ sed -e 's/resolv\.conf$/resolv.conf.dhclient/' /etc/dhclient-enter-hooks.dnsmasq > /etc/dhclient-enter-hooks
+ sed -e 's/\(nameserver[ tab]\+\)[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$/\1127.0.0.1/' /etc/resolv.conf.dnsmasq > /etc/resolv.conf
+ fi
+}
+
+function teardown_dhclient_enter_hooks() {
+ if [ -f /etc/dhclient-enter-hooks -a -f /etc/dhclient-enter-hooks.dnsmasq ]; then
+ if [ -f /etc/resolv.conf.dnsmasq ]; then
+ mv /etc/resolv.conf.dnsmasq /etc/resolv.conf
+ fi
+ mv /etc/dhclient-enter-hooks.dnsmasq /etc/dhclient-enter-hooks
+ fi
+}
+
# Source networking configuration.
. /etc/sysconfig/network
@@ -24,7 +43,7 @@
MAILHOSTNAME=""
# change this line if you want dns to get its upstream servers from
# somewhere other that /etc/resolv.conf
-RESOLV_CONF=""
+RESOLV_CONF="/etc/resolv.conf.dnsmasq"
# change this if you want dnsmasq to cache any "hostname" or "client-hostname" from
# a dhcpd's lease file
@@ -54,6 +73,7 @@
case "$1" in
start)
echo -n "Starting dnsmasq: "
+ setup_dhclient_enter_hooks
daemon $dnsmasq $OPTIONS
RETVAL=$?
echo
@@ -62,6 +82,7 @@
stop)
if test "x`pidof dnsmasq`" != x; then
echo -n "Shutting down dnsmasq: "
+ teardown_dhclient_enter_hooks
killproc dnsmasq
fi
RETVAL=$?
......@@ -5,7 +5,7 @@
###############################################################################
Name: dnsmasq
Version: 2.22
Version: 2.23
Release: 1
Copyright: GPL
Group: System Environment/Daemons
......
......@@ -5,7 +5,7 @@
###############################################################################
Name: dnsmasq
Version: 2.22
Version: 2.23
Release: 1
Copyright: GPL
Group: Productivity/Networking/DNS/Servers
......
......@@ -48,7 +48,8 @@ data under some circumstances.
.TP
.B \-k, --keep-in-foreground
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
or launchd.
.TP
.B \-d, --no-daemon
Debug mode: don't fork to the background, don't write a pid file,
......@@ -120,6 +121,9 @@ options does not matter and that
.B --except-interface
options always override the others.
.TP
.B \-2, --no-dhcp-interface=<interface name>
Do not provide DHCP on the specified interface, but do provide DNS service.
.TP
.B \-a, --listen-address=<ipaddr>
Listen on the given IP address(es). Both
.B \--interface
......@@ -201,6 +205,12 @@ time is the one used.
Don't read /etc/resolv.conf. Get upstream servers only from the command
line or the dnsmasq configuration file.
.TP
.B \-1, --enable-dbus
Allow dnsmasq configuration to be updated via DBus method calls. The
configuration which can be changed is upstream DNS servers (and
corressponding domains) and cache clear. Requires that dnsmasq has
been built with DBus support.
.TP
.B \-o, --strict-order
By default, dnsmasq will send queries to any of the upstream servers
it knows about and tries to favour servers to are known to
......@@ -212,11 +222,11 @@ Don't poll /etc/resolv.conf for changes.
.TP
.B \-D, --domain-needed
Tells dnsmasq to never forward queries for plain names, without dots
or domain parts, to upstream nameservers. If the name is not knowm
or domain parts, to upstream nameservers. If the name is not known
from /etc/hosts or DHCP then a "not found" answer is returned.
.TP
.B \-S, --server=[/[<domain>]/[domain/]][<ipaddr>[#<port>][@<source>[#<port>]]]
Specify IP address of upsream severs directly. Setting this flag does
Specify IP address of upstream severs directly. Setting this flag does
not suppress reading of /etc/resolv.conf, use -R to do that. If one or
more
optional domains are given, that server is used only for those domains
......@@ -302,13 +312,7 @@ is one and the defaults for
weight and priority are zero. Be careful if transposing data from BIND
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,
all that match are returned. Specifying at least one
.B --srv-host
option also turns on replies to SOA queries for the
domain given by the
.B --domain
option. The data in these is stereotyped, but is enough for resolvers
to deduce that the domain is a valid one for resolving SRV records.
all that match are returned.
.TP
.B \-Y, --txt-record=<name>[[,<text>],<text>]
Return a TXT DNS record. The value of TXT record is a set of strings,
......@@ -390,9 +394,10 @@ instance
.B --dhcp-host=00:20:e0:3b:13:af,ignore
This is
useful when there is another DHCP server on the network which should
be used by some machines. The net:<network-id> parameter enables DHCP options just
for this host in the same way as the the network-id in
.B dhcp-range.
be used by some machines. The net:<network-id> sets the network-id tag
whenever this dhcp-host directive is in use.
This can be used to selectively send DHCP options just
for this host.
Ethernet addresses (but not client-ids) may have
wildcard bytes, so for example
.B --dhcp-host=00:20:e0:3b:13:*,ignore
......@@ -434,7 +439,13 @@ of this flag. When the value is a decimal number, dnsmasq must determine how
large the data item is. It does this by examining the option number and/or the
value, but can be overriden by appending a single letter flag as follows:
b = one byte, s = two bytes, i = four bytes. This is mainly useful with
encapsulated vendor class options (see below) where dnsmasq cannot determine data size from the option number.
encapsulated vendor class options (see below) where dnsmasq cannot
determine data size from the option number. Option data which
consists solely of periods and digits will be interpreted by dnsmasq
as an IP address, and inserted into an option as such. To force a
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
.B --dhcp-option=66,"1.2.3.4"
Encapsulated Vendor-class options may also be specified using
--dhcp-option: for instance
......@@ -489,6 +500,12 @@ 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
to get a lease without a tedious timeout under all circumstances.
.TP
.B \-3, --bootp-dynamic
Enable dynamic allocation of IP addresses to BOOTP clients. Use this
with care, since each address allocated to a BOOTP client is leased
forever, and therefore becomes permanently unavailable for re-use by
other hosts.
.TP
.B \-l, --dhcp-leasefile=<path>
Use the specified file to store DHCP lease information. If this option
is given but no dhcp-range option is given then dnsmasq version 1
......@@ -502,7 +519,7 @@ Specifies the domain for the DHCP server. This has two effects;
firstly it causes the DHCP server to return the domain to any hosts
which request it, and secondly it sets the domain which it is legal
for DHCP-configured hosts to claim. The intention is to constrain hostnames so that an untrusted host on the LAN cannot advertise it's name via dhcp as e.g. "microsoft.com" and capture traffic not meant for it. If no domain suffix is specified, then any DHCP hostname with a domain part (ie with a period) will be disallowed and logged. If suffix is specified, then hostnames with a domain part are allowed, provided the domain part matches the suffix. In addition, when a suffix is set then hostnames without a domain part have the suffix added as an optional domain part. Eg on my network I can set
.B --domain-suffix=thekelleys.org.uk
.B --domain=thekelleys.org.uk
and have a machine whose DHCP hostname is "laptop". The IP address for that machine is available from
.B dnsmasq
both as "laptop" and "laptop.thekelleys.org.uk". If the domain is
......@@ -510,7 +527,7 @@ given as "#" then the domain is read from the first "search" directive
in /etc/resolv.conf (or equivalent).
.TP
.B \-E, --expand-hosts
Add the domain-suffix to simple names (without a period) in /etc/hosts
Add the domain to simple names (without a period) in /etc/hosts
in the same way as for DHCP-derived names.
.SH CONFIG FILE
At startup, dnsmasq reads
......@@ -522,13 +539,13 @@ FreeBSD, the file is
file consists of one option per line, exactly as the long options detailed
in the OPTIONS section but without the leading "--". Lines starting with # are comments and ignored. For
options which may only be specified once, the configuration file overrides
the command line. Use the --conf-file option to specify a different
the command line. Use the --conf-file (or -C) option to specify a different
configuration file. The conf-file option is also allowed in
configuration files, to include multiple configuration files. Only one
level of nesting is allowed. Quoting is allowed in a config file:
between " quotes the special meaning of , and # is removed and the
following escapes are allowed: \\\\ \\" \\t and \\n. The later two
corresponding to newline and tab.
between " quotes the special meanings of ,:. and # are removed and the
following escapes are allowed: \\\\ \\" \\t \\a \\b \\r and \\n. The later
corresponding to tab, bell, backspace, return and newline.
.SH NOTES
When it receives a SIGHUP,
.B dnsmasq
......
......@@ -10,7 +10,7 @@
# uneccessarily. If you have a dial-on-demand link they also stop
# these requests from bringing up the link uneccessarily.
# Never forward plain names (with a dot or domain part)
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
......@@ -62,8 +62,9 @@ bogus-priv
#user=
#group=
# If you want dnsmasq to listen for requests only on specified interfaces
# (and the loopback) give the name of the interface (eg eth0) here.
# If you want dnsmasq to listen for DHCP and DNS requests only on
# specified interfaces (and the loopback) give the name of the
# interface (eg eth0) here.
# Repeat the line for more than one interface.
#interface=
# Or you can specify which interface _not_ to listen on
......@@ -71,6 +72,10 @@ bogus-priv
# Or which to listen on by address (remember to include 127.0.0.1 if
# you use this.)
#listen-address=
# If you want dnsmasq to provide only DNS service on an interface,
# configure it as shown above, and then use the following line to
# disable DHCP on it.
#no-dhcp-interface=
# On systems which support it, dnsmasq binds the wildcard address,
# even when it is listening on only some interfaces. It then discards
......
......@@ -4,7 +4,7 @@
</HEAD>
<BODY BGCOLOR="WHITE">
<H1 ALIGN=center>Dnsmasq</H1>
Dnsmasq is lightweight, easy to configure DNS forwarder and DHCP
Dnsmasq is a lightweight, easy to configure DNS forwarder and DHCP
server. It is designed to provide DNS and, optionally, DHCP, to a
small network. It can serve the names of local machines which are
not in the global DNS. The DHCP server integrates with the DNS
......@@ -22,7 +22,7 @@ Supported platforms include Linux (with glibc and uclibc), *BSD and
Mac OS X.
Dnsmasq is included in at least the following Linux distributions:
Gentoo, Debian, Slackware, Suse,
Smoothwall, IP-Cop, floppyfw, Firebox, LEAF, Freesco, CoyoteLinux and
Smoothwall, IP-Cop, floppyfw, Firebox, LEAF, Freesco, fli4l, CoyoteLinux and
Clarkconnect. It is also available as a FreeBSD port and is used in
Linksys wireless routers and the m0n0wall project.
<P>
......@@ -103,8 +103,8 @@ bzip2 dnsmasq-zzz.tar
</PRE>
<H2>Links.</H2>
Ulrich Ivens has a nice HOWTO in German on installing dnsmasq at <A
HREF="http://howto.linux-hardware-shop.de/dnsmasq.html">http://howto.linux-hardware-shop.de/dnsmasq.html</A>
There is an article in German on dnsmasq at <A
HREF="http://www.linuxnetmag.com/de/issue7/m7dnsmasq1.html">http://www.linuxnetmag.com/de/issue7/m7dnsmasq1.html</A>
and Damien Raude-Morvan has one in French at <A HREF="http://www.drazzib.com/docs-dnsmasq.html">http://www.drazzib.com/docs-dnsmasq.html</A>
There is a good article about dnsmasq at <A
HREF="http://www.enterprisenetworkingplanet.com/netos/article.php/3377351">http://www.enterprisenetworkingplanet.com/netos/article.php/3377351</A>
......
# Uncomment this on Solaris.
#LIBS = -lsocket -lnsl
CFLAGS?= -O2
OBJS = cache.o rfc1035.o util.o option.o forward.o isc.o \
network.o dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o
.c.o: dnsmasq.h config.h
$(CC) $(CFLAGS) $(RPM_OPT_FLAGS) -Wall -W -c $*.c
dnsmasq : $(OBJS) dnsmasq.h config.h
$(CC) -o $@ $(OBJS) $(LIBS)
......@@ -59,12 +59,12 @@ void cache_init(int size, int logq)
hash_table[i] = NULL;
}
static struct crec **hash_bucket(unsigned char *name)
static struct crec **hash_bucket(char *name)
{
unsigned int c, val = 0;
/* don't use tolower and friends here - they may be messed up by LOCALE */
while((c = *name++))
while((c = (unsigned char) *name++))
if (c >= 'A' && c <= 'Z')
val += c + 'a' - 'A';
else
......@@ -579,12 +579,12 @@ static void read_hostsfile(char *filename, int opts, char *buff, char *domain_su
continue;
#ifdef HAVE_IPV6
if (inet_pton(AF_INET, token, &addr) == 1)
if (inet_pton(AF_INET, token, &addr) > 0)
{
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
addrlen = INADDRSZ;
}
else if (inet_pton(AF_INET6, token, &addr) == 1)
else if (inet_pton(AF_INET6, token, &addr) > 0)
{
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV6;
addrlen = IN6ADDRSZ;
......@@ -902,9 +902,9 @@ void log_query(unsigned short flags, char *name, struct all_addr *addr,
else if (flags & F_QUERY)
{
unsigned int i;
static struct {
static const struct {
unsigned int type;
char *name;
const char * const name;
} typestr[] = {
{ 1, "A" },
{ 2, "NS" },
......@@ -948,6 +948,9 @@ void log_query(unsigned short flags, char *name, struct all_addr *addr,
else
source = "cached";
if (strlen(name) == 0)
name = ".";
if ((flags & F_FORWARD) | (flags & F_NEG))
syslog(LOG_DEBUG, "%s %s %s %s", source, name, verb, addrbuff);
else if (flags & F_REVERSE)
......
......@@ -12,7 +12,7 @@
/* Author's email: simon@thekelleys.org.uk */
#define VERSION "2.22"
#define VERSION "2.23"
#define FTABSIZ 150 /* max number of outstanding requests */
#define MAX_PROCS 20 /* max no children for TCP requests */
......@@ -50,6 +50,10 @@
#define DHCP_SERVER_PORT 67
#define DHCP_CLIENT_PORT 68
/* DBUS interface specifics */
#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq"
#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
/* Logfile stuff - change this to change the options and facility */
/* debug is true if the --no-daemon flag is given */
#ifdef LOG_PERROR
......@@ -164,6 +168,11 @@ HAVE_RTNETLINK
back to the Berkley API at runtime if netlink support is not
configured into the kernel.
HAVE_DBUS
Define this if you want to link against libdbus, and have dnsmasq
define some methods to allow (re)configuration of the upstream DNS
servers via DBus.
NOTES:
For Linux you should define
HAVE_LINUX_IPV6_PROC
......@@ -201,6 +210,8 @@ NOTES:
# error HAVE_ISC_READER is not compatible with HAVE_BROKEN_RTC
#endif
#undef HAVE_DBUS
/* platform dependent options. */
/* Must preceed __linux__ since uClinux defines __linux__ too. */
......
/* dnsmasq is Copyright (c) 2000-2005 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.
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.
*/
#include "dnsmasq.h"
#ifdef HAVE_DBUS
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
struct watch {
DBusWatch *watch;
struct watch *next;
};
static dbus_bool_t add_watch(DBusWatch *watch, void *data)
{
struct daemon *daemon = data;
struct watch *w;
for (w = daemon->watches; w; w = w->next)
if (w->watch == watch)
return TRUE;
if (!(w = malloc(sizeof(struct watch))))
return FALSE;
w->watch = watch;
w->next = daemon->watches;
daemon->watches = w;
dbus_watch_set_data (watch, (void *)daemon, NULL);
return TRUE;
}
static void remove_watch(DBusWatch *watch, void *data)
{
struct daemon *daemon = data;
struct watch **up, *w;
for (up = &(daemon->watches), w = daemon->watches; w; w = w->next)
if (w->watch == watch)
{
*up = w->next;
free(w);
}
else
up = &(w->next);
}
static void dbus_read_servers(struct daemon *daemon, DBusMessage *message)
{
struct server *serv, *tmp, **up;
DBusMessageIter iter;
union mysockaddr addr, source_addr;
char *domain;
dbus_message_iter_init(message, &iter);
/* mark everything from DBUS */
for (serv = daemon->servers; serv; serv = serv->next)
if (serv->flags & SERV_FROM_DBUS)
serv->flags |= SERV_MARK;
while (1)
{
int skip = 0;
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT32)
{
u32 a;
dbus_message_iter_get_basic(&iter, &a);
dbus_message_iter_next (&iter);
#ifdef HAVE_SOCKADDR_SA_LEN
source_addr.in.sin_len = addr.in.sin_len = sizeof(struct sockaddr_in);
#endif
addr.in.sin_addr.s_addr = ntohl(a);
source_addr.in.sin_family = addr.in.sin_family = AF_INET;
addr.in.sin_port = htons(NAMESERVER_PORT);
source_addr.in.sin_addr.s_addr = INADDR_ANY;
source_addr.in.sin_port = htons(daemon->query_port);
}
else if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_BYTE)
{
unsigned char p[sizeof(struct in6_addr)];
unsigned int i;
skip = 1;
for(i = 0; i < sizeof(struct in6_addr); i++)
{
dbus_message_iter_get_basic(&iter, &p[i]);
dbus_message_iter_next (&iter);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BYTE)
break;
}
#ifndef HAVE_IPV6
syslog(LOG_WARNING, "attempt to set an IPv6 server address via DBus - no IPv6 support");
#else
if (i == sizeof(struct in6_addr)-1)
{
memcpy(&addr.in6.sin6_addr, p, sizeof(struct in6_addr));
#ifdef HAVE_SOCKADDR_SA_LEN
source_addr.in6.sin6_len = addr.in6.sin6_len = sizeof(struct sockaddr_in6);
#endif
source_addr.in6.sin6_family = addr.in6.sin6_family = AF_INET6;
addr.in6.sin6_port = htons(NAMESERVER_PORT);
source_addr.in6.sin6_flowinfo = addr.in6.sin6_flowinfo = htonl(0);
source_addr.in6.sin6_addr = in6addr_any;
source_addr.in6.sin6_port = htons(daemon->query_port);
skip = 0;
}
#endif
}
else
/* At the end */
break;
do {
if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
{
dbus_message_iter_get_basic(&iter, &domain);
dbus_message_iter_next (&iter);
}
else
domain = NULL;
if (!skip)
{
/* See if this is already there, and unmark */
for (serv = daemon->servers; serv; serv = serv->next)
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 = malloc(sizeof (struct server))))
{
/* Not found, create a new one. */
if (domain)
serv->domain = 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;
serv->sfd = NULL;
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. */
for (serv = daemon->servers, up = &daemon->servers; serv; serv = tmp)
{
tmp = serv->next;
if (serv->flags & SERV_MARK)
{
*up = serv->next;
free(serv);
}
else
up = &serv->next;
}
}
DBusHandlerResult message_handler (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
char *method = (char *)dbus_message_get_member(message);
struct daemon *daemon = (struct daemon *)user_data;
if (strcmp(method, "GetVersion") == 0)
{
char *v = VERSION;
DBusMessage *reply = dbus_message_new_method_return(message);
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)
{
syslog(LOG_INFO, "setting upstream servers from DBus");
dbus_read_servers(daemon, message);
check_servers(daemon);
}
else if (strcmp(method, "ClearCache") == 0)
clear_cache_and_reload(daemon, dnsmasq_time(daemon->uptime_fd));
else
return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
return (DBUS_HANDLER_RESULT_HANDLED);
}
/* returns NULL or error message, may fail silently if dbus daemon not yet up. */
char *dbus_init(struct daemon *daemon)
{
DBusConnection *connection = NULL;
DBusObjectPathVTable dnsmasq_vtable = {NULL, &message_handler, NULL, NULL, NULL, NULL };
DBusError dbus_error;
DBusMessage *message;
dbus_error_init (&dbus_error);
if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error)))
return NULL;
dbus_connection_set_exit_on_disconnect(connection, FALSE);
dbus_connection_set_watch_functions(connection, add_watch, remove_watch,
NULL, (void *)daemon, NULL);
dbus_error_init (&dbus_error);
dbus_bus_request_name (connection, DNSMASQ_SERVICE, 0, &dbus_error);
if (dbus_error_is_set (&dbus_error))
return (char *)dbus_error.message;
if (!dbus_connection_register_object_path(connection, DNSMASQ_PATH,
&dnsmasq_vtable, daemon))
return "could not register a DBus message handler";
daemon->dbus = connection;
if ((message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, "Up")))
dbus_connection_send(connection, message, NULL);
return NULL;
}
int set_dbus_listeners(struct daemon *daemon, int maxfd,
fd_set *rset, fd_set *wset, fd_set *eset)
{
struct watch *w;
for (w = daemon->watches; w; w = w->next)
if (dbus_watch_get_enabled(w->watch))
{
unsigned int flags = dbus_watch_get_flags(w->watch);
int fd = dbus_watch_get_fd(w->watch);
if (fd > maxfd)
maxfd = fd;
if (flags & DBUS_WATCH_READABLE)
FD_SET(fd, rset);
if (flags & DBUS_WATCH_WRITABLE)
FD_SET(fd, wset);
FD_SET(fd, eset);
}
return maxfd;
}
void check_dbus_listeners(struct daemon *daemon,
fd_set *rset, fd_set *wset, fd_set *eset)
{
DBusConnection *connection = (DBusConnection *)daemon->dbus;
struct watch *w;
for (w = daemon->watches; w; w = w->next)
if (dbus_watch_get_enabled(w->watch))
{
unsigned int flags = 0;
int fd = dbus_watch_get_fd(w->watch);
if (FD_ISSET(fd, rset))
flags |= DBUS_WATCH_READABLE;
if (FD_ISSET(fd, wset))
flags |= DBUS_WATCH_WRITABLE;
if (FD_ISSET(fd, eset))
flags |= DBUS_WATCH_ERROR;
if (flags != 0)
dbus_watch_handle(w->watch, flags);
}
if (connection)
{
dbus_connection_ref (connection);
while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS);
dbus_connection_unref (connection);
}
}
#endif
......@@ -56,7 +56,7 @@ void dhcp_init(struct daemon *daemon)
if ((fd = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1 ||
(flags = fcntl(fd, F_GETFL, 0)) == -1 ||
fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1 ||
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &oneopt, sizeof(oneopt)) ||
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &oneopt, sizeof(oneopt)) == -1 ||
setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &zeroopt, sizeof(zeroopt)) == -1)
die("cannot create ICMP raw socket: %s.", NULL);
......@@ -102,7 +102,7 @@ void dhcp_init(struct daemon *daemon)
and get a terminating zero added */
daemon->dhcp_buff = safe_malloc(256);
daemon->dhcp_buff2 = safe_malloc(256);
daemon->ping_results = NULL;
}
void dhcp_packet(struct daemon *daemon, time_t now)
......@@ -191,6 +191,10 @@ void dhcp_packet(struct daemon *daemon, time_t now)
for (tmp = daemon->if_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
return;
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
if (tmp->name && (strcmp(tmp->name, ifr.ifr_name) == 0))
return;
if (daemon->if_names || daemon->if_addrs)
{
......@@ -333,6 +337,7 @@ void dhcp_packet(struct daemon *daemon, time_t now)
#else
struct sockaddr_ll dest;
memset(&dest, 0, sizeof(dest));
dest.sll_family = AF_PACKET;
dest.sll_halen = ETHER_ADDR_LEN;
dest.sll_ifindex = iface_index;
......@@ -495,7 +500,8 @@ int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool)
}
int address_allocate(struct dhcp_context *context, struct daemon *daemon,
struct in_addr *addrp, unsigned char *hwaddr, struct dhcp_netid *netids)
struct in_addr *addrp, unsigned char *hwaddr,
struct dhcp_netid *netids, time_t now)
{
/* Find a free address: exclude anything in use and anything allocated to
a particular hwaddr/clientid/hostname in our configuration.
......@@ -528,12 +534,47 @@ int address_allocate(struct dhcp_context *context, struct daemon *daemon,
if (!lease_find_by_addr(addr) &&
!config_find_by_address(daemon->dhcp_conf, addr))
{
struct ping_result *r, *victim = NULL;
int count;
/* check if we failed to ping addr sometime in the last
30s. If so, assume the same situation still exists.
This avoids problems when a stupid client bangs
on us repeatedly. As a final check, is we did more
than six ping checks in the last 30s, we are in
high-load mode, so don't do any more. */
for (count = 0, r = daemon->ping_results; r; r = r->next)
if (difftime(now, r->time) > 30.0)
victim = r; /* old record */
else if (++count == 6 || r->addr.s_addr == addr.s_addr)
{
*addrp = addr;
return 1;
}
if (icmp_ping(daemon, addr))
/* perturb address selection so that we are
/* address in use: perturb address selection so that we are
less likely to try this address again. */
c->addr_epoch++;
else
{
/* at this point victim may hold an expired record */
if (!victim)
{
if ((victim = malloc(sizeof(struct ping_result))))
{
victim->next = daemon->ping_results;
daemon->ping_results = victim;
}
}
/* record that this address is OK for 30s
without more ping checks */
if (victim)
{
victim->addr = addr;
victim->time = now;
}
*addrp = addr;
return 1;
}
......@@ -548,7 +589,7 @@ int address_allocate(struct dhcp_context *context, struct daemon *daemon,
}
if (netids)
return address_allocate(context, daemon, addrp, hwaddr, NULL);
return address_allocate(context, daemon, addrp, hwaddr, NULL, now);
return 0;
}
......@@ -590,14 +631,16 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
return config;
}
for (config = configs; config; config = config->next)
if ((config->flags & CONFIG_HWADDR) &&
config->wildcard_mask == 0 &&
memcmp(config->hwaddr, hwaddr, ETHER_ADDR_LEN) == 0 &&
is_addr_in_context(context, config))
return config;
if (hwaddr)
for (config = configs; config; config = config->next)
if ((config->flags & CONFIG_HWADDR) &&
config->wildcard_mask == 0 &&
memcmp(config->hwaddr, hwaddr, ETHER_ADDR_LEN) == 0 &&
is_addr_in_context(context, config))
return config;
if (hostname && context)
for (config = configs; config; config = config->next)
if ((config->flags & CONFIG_NAME) &&
......@@ -605,20 +648,21 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
is_addr_in_context(context, config))
return config;
for (config = configs; config; config = config->next)
if ((config->flags & CONFIG_HWADDR) &&
config->wildcard_mask != 0 &&
is_addr_in_context(context, config))
{
int i;
unsigned int mask = config->wildcard_mask;
for (i = ETHER_ADDR_LEN - 1; i >= 0; i--, mask = mask >> 1)
if (mask & 1)
config->hwaddr[i] = hwaddr[i];
if (memcmp(config->hwaddr, hwaddr, ETHER_ADDR_LEN) == 0)
return config;
}
if (hwaddr)
for (config = configs; config; config = config->next)
if ((config->flags & CONFIG_HWADDR) &&
config->wildcard_mask != 0 &&
is_addr_in_context(context, config))
{
int i;
unsigned int mask = config->wildcard_mask;
for (i = ETHER_ADDR_LEN - 1; i >= 0; i--, mask = mask >> 1)
if (mask & 1)
config->hwaddr[i] = hwaddr[i];
if (memcmp(config->hwaddr, hwaddr, ETHER_ADDR_LEN) == 0)
return config;
}
return NULL;
}
......@@ -632,6 +676,8 @@ void dhcp_read_ethers(struct daemon *daemon)
unsigned char hwaddr[ETHER_ADDR_LEN];
struct dhcp_config *config, *configs = daemon->dhcp_conf;
int count = 0;
addr.s_addr = 0; /* eliminate warning */
if (!f)
{
......@@ -731,7 +777,9 @@ 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. */
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. */
struct dhcp_config *config;
struct crec *crec;
......@@ -742,8 +790,14 @@ void dhcp_update_configs(struct dhcp_config *configs)
(crec = cache_find_by_name(NULL, config->hostname, 0, F_IPV4)) &&
(crec->flags & F_HOSTS))
{
config->addr = crec->addr.addr.addr.addr4;
config->flags |= CONFIG_ADDR;
if (config_find_by_address(configs, crec->addr.addr.addr.addr4))
syslog(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;
}
}
}
......
This diff is collapsed.
......@@ -110,6 +110,8 @@
#define OPT_NO_FORK 65536
#define OPT_AUTHORITATIVE 131072
#define OPT_LOCALISE 262144
#define OPT_DBUS 524288
#define OPT_BOOTP_DYNAMIC 1048576
struct all_addr {
union {
......@@ -133,7 +135,8 @@ struct doctor {
struct mx_srv_record {
char *name, *target;
int issrv, srvport, priority, weight, offset;
int issrv, srvport, priority, weight;
unsigned int offset;
struct mx_srv_record *next;
};
......@@ -214,6 +217,8 @@ union mysockaddr {
#define SERV_HAS_DOMAIN 16 /* server for one domain only */
#define SERV_FOR_NODOTS 32 /* server for names with no domain part only */
#define SERV_WARNED_RECURSIVE 64 /* avoid warning spam */
#define SERV_FROM_DBUS 128 /* 1 if source is DBus */
#define SERV_MARK 256 /* for mark-and-delete */
#define SERV_TYPE (SERV_HAS_DOMAIN | SERV_FOR_NODOTS)
......@@ -255,8 +260,8 @@ struct iname {
/* resolv-file parms from command-line */
struct resolvc {
struct resolvc *next;
int is_default;
int logged;
int is_default, logged;
time_t mtime;
char *name;
};
......@@ -379,6 +384,11 @@ struct udp_dhcp_packet {
} data;
};
struct ping_result {
struct in_addr addr;
time_t time;
struct ping_result *next;
};
struct daemon {
/* datastuctures representing the command-line and
......@@ -394,7 +404,7 @@ struct daemon {
char *username, *groupname;
char *domain_suffix;
char *runfile;
struct iname *if_names, *if_addrs, *if_except;
struct iname *if_names, *if_addrs, *if_except, *dhcp_except;
struct bogus_addr *bogus_addr;
struct server *servers;
int cachesize;
......@@ -417,6 +427,7 @@ struct daemon {
int packet_buff_sz; /* size of above */
char *namebuff; /* MAXDNAME size buffer */
struct serverfd *sfds;
struct irec *interfaces;
struct listener *listeners;
struct server *last_server;
int uptime_fd;
......@@ -428,6 +439,15 @@ struct daemon {
#endif
struct udp_dhcp_packet *dhcp_packet;
char *dhcp_buff, *dhcp_buff2;
struct ping_result *ping_results;
/* DBus stuff */
#ifdef HAVE_DBUS
/* void * here to avoid depending on dbus headers outside dbus.c */
void *dbus;
struct watch *watches;
#endif
};
/* cache.c */
......@@ -472,35 +492,35 @@ int resize_packet(HEADER *header, unsigned int plen,
unsigned short rand16(void);
int legal_char(char c);
int canonicalise(char *s);
int atoi_check(char *a, int *res);
unsigned char *do_rfc1035_name(unsigned char *p, char *sval);
void die(char *message, char *arg1);
void complain(char *message, int lineno, char *file);
void *safe_malloc(size_t size);
char *safe_string_alloc(char *cp);
int sa_len(union mysockaddr *addr);
int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
int hostname_isequal(unsigned char *a, unsigned char *b);
int hostname_isequal(char *a, char *b);
time_t dnsmasq_time(int fd);
int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
int retry_send(void);
void prettyprint_time(char *buf, unsigned int t);
int prettyprint_addr(union mysockaddr *addr, char *buf);
int parse_hex(char *in, unsigned char *out, int maxlen,
unsigned int *wildcard_mask);
/* option.c */
struct daemon *read_opts (int argc, char **argv);
struct daemon *read_opts (int argc, char **argv, char *compile_opts);
/* forward.c */
void forward_init(int first);
void reply_query(struct serverfd *sfd, struct daemon *daemon, time_t now);
void receive_query(struct listener *listen, struct daemon *daemon, time_t now);
char *tcp_request(struct daemon *daemon, int confd, time_t now,
struct in_addr local_addr, struct in_addr netmask);
unsigned char *tcp_request(struct daemon *daemon, int confd, time_t now,
struct in_addr local_addr, struct in_addr netmask);
/* network.c */
struct serverfd *allocate_sfd(union mysockaddr *addr, struct serverfd **sfds);
void reload_servers(char *fname, struct daemon *daemon);
void check_servers(struct daemon *daemon, struct irec *interfaces);
void check_servers(struct daemon *daemon);
int enumerate_interfaces(struct daemon *daemon, struct irec **chainp,
union mysockaddr *test_addrp, struct in_addr *netmaskp);
struct listener *create_wildcard_listeners(int port);
......@@ -515,7 +535,7 @@ struct dhcp_context *narrow_context(struct dhcp_context *context, struct in_addr
int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool);
int address_allocate(struct dhcp_context *context, struct daemon *daemon,
struct in_addr *addrp, unsigned char *hwaddr,
struct dhcp_netid *netids);
struct dhcp_netid *netids, time_t now);
struct dhcp_config *find_config(struct dhcp_config *configs,
struct dhcp_context *context,
unsigned char *clid, int clid_len,
......@@ -551,6 +571,7 @@ int dhcp_reply(struct daemon *daemon, struct dhcp_context *context, char *iface_
/* dnsmasq.c */
int icmp_ping(struct daemon *daemon, struct in_addr addr);
void clear_cache_and_reload(struct daemon *daemon, time_t now);
/* isc.c */
#ifdef HAVE_ISC_READER
......@@ -564,3 +585,12 @@ int netlink_process(struct daemon *daemon, int index,
struct in_addr relay, struct in_addr primary,
struct dhcp_context **retp);
#endif
/* dbus.c */
#ifdef HAVE_DBUS
char *dbus_init(struct daemon *daemon);
void check_dbus_listeners(struct daemon *daemon,
fd_set *rset, fd_set *wset, fd_set *eset);
int set_dbus_listeners(struct daemon *daemon, int maxfd,
fd_set *rset, fd_set *wset, fd_set *eset);
#endif
......@@ -89,9 +89,8 @@ static void send_from(int fd, int nowild, char *packet, int len,
cmptr->cmsg_type = IP_SENDSRCADDR;
#endif
}
#ifdef HAVE_IPV6
else
#ifdef HAVE_IPV
{
struct in6_pktinfo *pkt = (struct in6_pktinfo *)CMSG_DATA(cmptr);
pkt->ipi6_ifindex = iface; /* Need iface for IPv6 to handle link-local addrs */
......@@ -100,6 +99,8 @@ static void send_from(int fd, int nowild, char *packet, int len,
cmptr->cmsg_type = IPV6_PKTINFO;
cmptr->cmsg_level = IPV6_LEVEL;
}
#else
iface = 0; /* eliminate warning */
#endif
}
......@@ -134,7 +135,7 @@ static unsigned short search_servers(struct daemon *daemon, time_t now, struct a
for (serv = daemon->servers; serv; serv=serv->next)
/* domain matches take priority over NODOTS matches */
if ((serv->flags & SERV_FOR_NODOTS) && *type != SERV_HAS_DOMAIN && !strchr(qdomain, '.'))
if ((serv->flags & SERV_FOR_NODOTS) && *type != SERV_HAS_DOMAIN && !strchr(qdomain, '.') && namelen != 0)
{
unsigned short sflag = serv->addr.sa.sa_family == AF_INET ? F_IPV4 : F_IPV6;
*type = SERV_FOR_NODOTS;
......@@ -194,7 +195,7 @@ static unsigned short search_servers(struct daemon *daemon, time_t now, struct a
else
log_query(F_CONFIG | F_FORWARD | flags, qdomain, *addrpp, 0, NULL, 0);
}
else if (qtype && (daemon->options & OPT_NODOTS_LOCAL) && !strchr(qdomain, '.'))
else if (qtype && (daemon->options & OPT_NODOTS_LOCAL) && !strchr(qdomain, '.') && namelen != 0)
flags = F_NXDOMAIN;
if (flags == F_NXDOMAIN && check_for_local_domain(qdomain, now, daemon))
......@@ -215,13 +216,13 @@ static void forward_query(struct daemon *daemon, int udpfd, union mysockaddr *ud
char *domain = NULL;
int type = 0;
struct all_addr *addrp = NULL;
unsigned int crc = questions_crc(header, (unsigned int)plen, daemon->namebuff);
unsigned short flags = 0;
unsigned short gotname = extract_request(header, (unsigned int)plen, daemon->namebuff, NULL);
struct server *start = NULL;
unsigned int crc = questions_crc(header,(unsigned int)plen, daemon->namebuff);
/* may be recursion not speced or no servers available. */
if (!header->rd || !daemon->servers)
/* may be no servers available. */
if (!daemon->servers)
forward = NULL;
else if ((forward = lookup_frec_by_sender(ntohs(header->id), udpaddr, crc)))
{
......@@ -369,16 +370,8 @@ static int process_reply(struct daemon *daemon, HEADER *header, time_t now,
if (!header->ra && header->rcode == NOERROR && ntohs(header->ancount) == 0 &&
server && !(server->flags & SERV_WARNED_RECURSIVE))
{
char addrbuff[ADDRSTRLEN];
#ifdef HAVE_IPV6
if (server->addr.sa.sa_family == AF_INET)
inet_ntop(AF_INET, &server->addr.in.sin_addr, addrbuff, ADDRSTRLEN);
else if (server->addr.sa.sa_family == AF_INET6)
inet_ntop(AF_INET6, &server->addr.in6.sin6_addr, addrbuff, ADDRSTRLEN);
#else
strcpy(addrbuff, inet_ntoa(server->addr.in.sin_addr));
#endif
syslog(LOG_WARNING, "nameserver %s refused to do a recursive query", addrbuff);
prettyprint_addr(&server->addr, daemon->namebuff);
syslog(LOG_WARNING, "nameserver %s refused to do a recursive query", daemon->namebuff);
if (!(daemon->options & OPT_LOG))
server->flags |= SERV_WARNED_RECURSIVE;
}
......@@ -520,7 +513,10 @@ void receive_query(struct listener *listen, struct daemon *daemon, time_t now)
netmask = listen->iface->netmask;
}
else
dst_addr_4.s_addr = 0;
{
dst_addr_4.s_addr = 0;
netmask.s_addr = 0;
}
iov[0].iov_base = daemon->packet;
iov[0].iov_len = daemon->edns_pktsz;
......@@ -657,7 +653,7 @@ void receive_query(struct listener *listen, struct daemon *daemon, time_t now)
header, n, now);
}
static int read_write(int fd, char *packet, int size, int rw)
static int read_write(int fd, unsigned char *packet, int size, int rw)
{
int n, done;
......@@ -686,14 +682,14 @@ static int read_write(int fd, char *packet, int size, int rw)
blocking as neccessary, and then return. Note, need to be a bit careful
about resources for debug mode, when the fork is suppressed: that's
done by the caller. */
char *tcp_request(struct daemon *daemon, int confd, time_t now,
struct in_addr local_addr, struct in_addr netmask)
unsigned char *tcp_request(struct daemon *daemon, int confd, time_t now,
struct in_addr local_addr, struct in_addr netmask)
{
int size = 0, m;
unsigned short qtype, gotname;
unsigned char c1, c2;
/* Max TCP packet + slop */
char *packet = malloc(65536 + MAXDNAME + RRFIXEDSZ);
unsigned char *packet = malloc(65536 + MAXDNAME + RRFIXEDSZ);
HEADER *header;
struct server *last_server;
......
......@@ -136,8 +136,8 @@ void load_dhcp(struct daemon *daemon, time_t now)
it is noted that it might not be entirely accurate for odd seconds.
Since we're trying to get the same answer as dhcpd, that's just
fine here. */
static int months [11] = { 31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334 };
static const int months [11] = { 31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334 };
time_t time = ((((((365 * (lease_time.tm_year - 1970) + /* Days in years since '70 */
(lease_time.tm_year - 1969) / 4 + /* Leap days since '70 */
(lease_time.tm_mon > 1 /* Days in months this year */
......
......@@ -71,9 +71,9 @@ void lease_init(struct daemon *daemon, time_t now)
if (strcmp(daemon->packet, "*") == 0)
clid_len = 0;
else
clid_len = parse_hex(daemon->packet, daemon->packet, 255, NULL);
clid_len = parse_hex(daemon->packet, (unsigned char *)daemon->packet, 255, NULL);
if (!(lease = lease_allocate(hwaddr, daemon->packet, clid_len, addr)))
if (!(lease = lease_allocate(hwaddr, (unsigned char *)daemon->packet, clid_len, addr)))
die ("too many stored leases", NULL);
lease->expires = expires;
......
......@@ -33,7 +33,8 @@ static int iface_allowed(struct daemon *daemon, struct irec *iface,
if (!lo)
{
lo = safe_malloc(sizeof(struct iname));
lo->name = safe_string_alloc(name);
lo->name = safe_malloc(strlen(name)+1);
strcpy(lo->name, name);
lo->isloop = lo->used = 1;
lo->next = daemon->if_names;
daemon->if_names = lo;
......@@ -100,6 +101,8 @@ int enumerate_interfaces(struct daemon *daemon, struct irec **chainp,
int fd = socket(PF_INET, SOCK_DGRAM, 0);
struct in_addr netmask;
int ret = 0;
netmask.s_addr = 0; /* eliminate warning */
if (fd == -1)
return 0;
......@@ -262,7 +265,7 @@ int enumerate_interfaces(struct daemon *daemon, struct irec **chainp,
return ret;
}
#ifdef HAVE_IPV6
#if defined(HAVE_IPV6) && (defined(IP_PKTINFO) || (defined(IP_RECVDSTADDR) && defined(IP_RECVIF) && defined(IP_SENDSRCADDR)))
static int create_ipv6_listener(struct listener **link, int port)
{
union mysockaddr addr;
......@@ -330,6 +333,7 @@ static int create_ipv6_listener(struct listener **link, int port)
struct listener *create_wildcard_listeners(int port)
{
#if !(defined(IP_PKTINFO) || (defined(IP_RECVDSTADDR) && defined(IP_RECVIF) && defined(IP_SENDSRCADDR)))
port = 0; /* eliminate warning */
return NULL;
#else
union mysockaddr addr;
......@@ -434,7 +438,11 @@ struct listener *create_bound_listeners(struct irec *interfaces, int port)
}
else
#endif
die("failed to bind listening socket: %s", NULL);
{
char addrbuff[ADDRSTRLEN];
prettyprint_addr(&iface->addr, addrbuff);
die("failed to bind listening socket for %s: %s", addrbuff);
}
}
else
{
......@@ -486,9 +494,8 @@ struct serverfd *allocate_sfd(union mysockaddr *addr, struct serverfd **sfds)
return sfd;
}
void check_servers(struct daemon *daemon, struct irec *interfaces)
void check_servers(struct daemon *daemon)
{
char addrbuff[ADDRSTRLEN];
struct irec *iface;
struct server *new, *tmp, *ret = NULL;
int port = 0;
......@@ -504,27 +511,14 @@ void check_servers(struct daemon *daemon, struct irec *interfaces)
if (!(new->flags & (SERV_LITERAL_ADDRESS | SERV_NO_ADDR)))
{
#ifdef HAVE_IPV6
if (new->addr.sa.sa_family == AF_INET)
{
inet_ntop(AF_INET, &new->addr.in.sin_addr, addrbuff, ADDRSTRLEN);
port = ntohs(new->addr.in.sin_port);
}
else if (new->addr.sa.sa_family == AF_INET6)
{
inet_ntop(AF_INET6, &new->addr.in6.sin6_addr, addrbuff, ADDRSTRLEN);
port = ntohs(new->addr.in6.sin6_port);
}
#else
strcpy(addrbuff, inet_ntoa(new->addr.in.sin_addr));
port = ntohs(new->addr.in.sin_port);
#endif
for (iface = interfaces; iface; iface = iface->next)
port = prettyprint_addr(&new->addr, daemon->namebuff);
for (iface = daemon->interfaces; iface; iface = iface->next)
if (sockaddr_isequal(&new->addr, &iface->addr))
break;
if (iface)
{
syslog(LOG_WARNING, "ignoring nameserver %s - local interface", addrbuff);
syslog(LOG_WARNING, "ignoring nameserver %s - local interface", daemon->namebuff);
free(new);
continue;
}
......@@ -533,7 +527,7 @@ void check_servers(struct daemon *daemon, struct irec *interfaces)
if (!new->sfd && !(new->sfd = allocate_sfd(&new->source_addr, &daemon->sfds)))
{
syslog(LOG_WARNING,
"ignoring nameserver %s - cannot make/bind socket: %m", addrbuff);
"ignoring nameserver %s - cannot make/bind socket: %m", daemon->namebuff);
free(new);
continue;
}
......@@ -554,10 +548,10 @@ void check_servers(struct daemon *daemon, struct irec *interfaces)
if (new->flags & SERV_NO_ADDR)
syslog(LOG_INFO, "using local addresses only for %s %s", s1, s2);
else if (!(new->flags & SERV_LITERAL_ADDRESS))
syslog(LOG_INFO, "using nameserver %s#%d for %s %s", addrbuff, port, s1, s2);
syslog(LOG_INFO, "using nameserver %s#%d for %s %s", daemon->namebuff, port, s1, s2);
}
else
syslog(LOG_INFO, "using nameserver %s#%d", addrbuff, port);
syslog(LOG_INFO, "using nameserver %s#%d", daemon->namebuff, port);
}
daemon->servers = ret;
......@@ -611,7 +605,7 @@ void reload_servers(char *fname, struct daemon *daemon)
continue;
#ifdef HAVE_IPV6
if (inet_pton(AF_INET, token, &addr.in.sin_addr))
if (inet_pton(AF_INET, token, &addr.in.sin_addr) > 0)
#else
if ((addr.in.sin_addr.s_addr = inet_addr(token)) != (in_addr_t) -1)
#endif
......@@ -625,7 +619,7 @@ void reload_servers(char *fname, struct daemon *daemon)
source_addr.in.sin_port = htons(daemon->query_port);
}
#ifdef HAVE_IPV6
else if (inet_pton(AF_INET6, token, &addr.in6.sin6_addr))
else if (inet_pton(AF_INET6, token, &addr.in6.sin6_addr) > 0)
{
#ifdef HAVE_SOCKADDR_SA_LEN
source_addr.in6.sin6_len = addr.in6.sin6_len = sizeof(struct sockaddr_in6);
......
This diff is collapsed.
......@@ -14,13 +14,13 @@
static int add_resource_record(HEADER *header, char *limit, int *truncp,
unsigned int nameoffset, unsigned char **pp,
unsigned long ttl, int *offset, unsigned short type,
unsigned long ttl, unsigned int *offset, unsigned short type,
unsigned short class, char *format, ...);
static int extract_name(HEADER *header, unsigned int plen, unsigned char **pp,
unsigned char *name, int isExtract)
char *name, int isExtract)
{
unsigned char *cp = name, *p = *pp, *p1 = NULL;
unsigned char *cp = (unsigned char *)name, *p = *pp, *p1 = NULL;
unsigned int j, l, hops = 0;
int retvalue = 1;
......@@ -68,7 +68,7 @@ static int extract_name(HEADER *header, unsigned int plen, unsigned char **pp,
digs = ((count-1)>>2)+1;
/* output is \[x<hex>/siz]. which is digs+9 chars */
if (cp - name + digs + 9 >= MAXDNAME)
if (cp - (unsigned char *)name + digs + 9 >= MAXDNAME)
return 0;
if (p - (unsigned char *)header + ((count-1)>>3) + 1u >= plen)
return 0;
......@@ -86,13 +86,13 @@ static int extract_name(HEADER *header, unsigned int plen, unsigned char **pp,
*cp++ = dig < 10 ? dig + '0' : dig + 'A' - 10;
}
cp += sprintf(cp, "/%d]", count);
cp += sprintf((char *)cp, "/%d]", count);
/* do this here to overwrite the zero char from sprintf */
*cp++ = '.';
}
else
{ /* label_type = 0 -> label. */
if (cp - name + l + 1 >= MAXDNAME)
if (cp - (unsigned char *)name + l + 1 >= MAXDNAME)
return 0;
if (p - (unsigned char *)header + 1u >= plen)
return 0;
......@@ -349,7 +349,7 @@ unsigned int questions_crc(HEADER *header, unsigned int plen, char *name)
if (!extract_name(header, plen, &p, name, 1))
return crc; /* bad packet */
for (p1 = name; *p1; p1++)
for (p1 = (unsigned char *)name; *p1; p1++)
{
int i = 8;
char c = *p1;
......@@ -883,7 +883,7 @@ int check_for_bogus_wildcard(HEADER *header, unsigned int qlen, char *name,
}
static int add_resource_record(HEADER *header, char *limit, int *truncp, unsigned int nameoffset, unsigned char **pp,
unsigned long ttl, int *offset, unsigned short type, unsigned short class, char *format, ...)
unsigned long ttl, unsigned int *offset, unsigned short type, unsigned short class, char *format, ...)
{
va_list ap;
unsigned char *sav, *p = *pp;
......@@ -936,19 +936,10 @@ static int add_resource_record(HEADER *header, char *limit, int *truncp, unsigne
/* get domain-name answer arg and store it in RDATA field */
if (offset)
*offset = p - (unsigned char *)header;
sval = va_arg(ap, char *);
while (sval && *sval)
{
unsigned char *cp = p++;
for (j = 0; *sval && (*sval != '.'); sval++, j++)
*p++ = *sval;
*cp = j;
if (*sval)
sval++;
}
p = do_rfc1035_name(p, va_arg(ap, char *));
*p++ = 0;
break;
case 't':
usval = va_arg(ap, int);
sval = va_arg(ap, char *);
......@@ -1126,17 +1117,31 @@ int answer_request(HEADER *header, char *limit, unsigned int qlen, struct daemon
for (flag = F_IPV4; flag; flag = (flag == F_IPV4) ? F_IPV6 : 0)
{
unsigned short type = T_A;
if (flag == F_IPV6)
#ifdef HAVE_IPV6
type = T_AAAA;
type = T_AAAA;
#else
break;
break;
#endif
if (qtype != type && qtype != T_ANY)
continue;
/* Check for "A for A" queries. */
if (qtype == T_A && (addr.addr.addr4.s_addr = inet_addr(name)) != (in_addr_t) -1)
{
ans = 1;
if (!dryrun)
{
log_query(F_FORWARD | F_CONFIG | F_IPV4, name, &addr, 0, NULL, 0);
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
daemon->local_ttl, NULL, type, C_IN, "4", &addr))
anscount++;
}
continue;
}
cname_restart:
if ((crecp = cache_find_by_name(NULL, name, now, flag | F_CNAME)))
{
......@@ -1231,7 +1236,7 @@ int answer_request(HEADER *header, char *limit, unsigned int qlen, struct daemon
ans = found = 1;
if (!dryrun)
{
int offset;
unsigned int offset;
log_query(F_CNAME | F_FORWARD | F_CONFIG | F_IPV4, name, NULL, 0, NULL, 0);
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
&offset, T_MX, C_IN, "sd", rec->weight, rec->target))
......@@ -1268,7 +1273,7 @@ int answer_request(HEADER *header, char *limit, unsigned int qlen, struct daemon
found = ans = 1;
if (!dryrun)
{
int offset;
unsigned int offset;
log_query(F_CNAME | F_FORWARD | F_CONFIG | F_IPV6, name, NULL, 0, NULL, 0);
if (add_resource_record(header, limit, &trunc, nameoffset, &ansp, daemon->local_ttl,
&offset, T_SRV, C_IN, "sssd",
......
This diff is collapsed.
......@@ -85,18 +85,6 @@ unsigned short rand16(void)
return( (unsigned short) (rand() >> 15) );
}
int atoi_check(char *a, int *res)
{
char *p;
for (p = a; *p; p++)
if (*p < '0' || *p > '9')
return 0;
*res = atoi(a);
return 1;
}
int legal_char(char c)
{
/* check for legal char a-z A-Z 0-9 -
......@@ -125,15 +113,33 @@ int canonicalise(char *s)
s[l-1] = 0;
}
while ((c = *s++))
if (c == '.')
dotgap = 0;
else if (!legal_char(c) || (++dotgap > MAXLABEL))
return 0;
while ((c = *s))
{
if (c == '.')
dotgap = 0;
else if (!legal_char(c) || (++dotgap > MAXLABEL))
return 0;
s++;
}
return 1;
}
unsigned char *do_rfc1035_name(unsigned char *p, char *sval)
{
int j;
while (sval && *sval)
{
unsigned char *cp = p++;
for (j = 0; *sval && (*sval != '.'); sval++, j++)
*p++ = *sval;
*cp = j;
if (*sval)
sval++;
}
return p;
}
/* for use during startup */
void *safe_malloc(size_t size)
{
......@@ -143,20 +149,7 @@ void *safe_malloc(size_t size)
die("could not get memory", NULL);
return ret;
}
char *safe_string_alloc(char *cp)
{
char *ret = NULL;
if (cp && strlen(cp) != 0)
{
ret = safe_malloc(strlen(cp)+1);
strcpy(ret, cp);
}
return ret;
}
}
static void log_err(char *message, char *arg1)
{
......@@ -176,8 +169,8 @@ void complain(char *message, int lineno, char *file)
{
char buff[256];
sprintf(buff, "%s at line %d of %s", message, lineno, file);
log_err(buff, NULL);
sprintf(buff, "%s at line %d of %%s", message, lineno);
log_err(buff, file);
}
void die(char *message, char *arg1)
......@@ -221,13 +214,13 @@ int sa_len(union mysockaddr *addr)
}
/* don't use strcasecmp and friends here - they may be messed up by LOCALE */
int hostname_isequal(unsigned char *a, unsigned char *b)
int hostname_isequal(char *a, char *b)
{
unsigned int c1, c2;
do {
c1 = *a++;
c2 = *b++;
c1 = (unsigned char) *a++;
c2 = (unsigned char) *b++;
if (c1 >= 'A' && c1 <= 'Z')
c1 += 'a' - 'A';
......@@ -250,6 +243,9 @@ time_t dnsmasq_time(int fd)
char buf[30];
lseek(fd, 0, SEEK_SET);
read(fd, buf, 30);
/* ensure the time is terminated even if /proc/uptime sends something unexpected */
buf[29] = 0;
read(fd, buf, 30);
return (time_t)atol(buf);
#else
fd = 0; /* stop warning */
......@@ -279,6 +275,30 @@ int retry_send(void)
return 0;
}
/* returns port number from address */
int prettyprint_addr(union mysockaddr *addr, char *buf)
{
int port = 0;
#ifdef HAVE_IPV6
if (addr->sa.sa_family == AF_INET)
{
inet_ntop(AF_INET, &addr->in.sin_addr, buf, ADDRSTRLEN);
port = ntohs(addr->in.sin_port);
}
else if (addr->sa.sa_family == AF_INET6)
{
inet_ntop(AF_INET6, &addr->in6.sin6_addr, buf, ADDRSTRLEN);
port = ntohs(addr->in6.sin6_port);
}
#else
strcpy(buf, inet_ntoa(addr->in.sin_addr));
port = ntohs(addr->in.sin_port);
#endif
return port;
}
void prettyprint_time(char *buf, unsigned int t)
{
if (t == 0xffffffff)
......@@ -286,7 +306,9 @@ void prettyprint_time(char *buf, unsigned int t)
else
{
unsigned int x, p = 0;
if ((x = t/3600))
if ((x = t/86400))
p += sprintf(&buf[p], "%dd", x);
if ((x = (t/3600)%24))
p += sprintf(&buf[p], "%dh", x);
if ((x = (t/60)%60))
p += sprintf(&buf[p], "%dm", x);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment