mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 02:08:24 +00:00
import of dnsmasq-2.33.tar.gz
This commit is contained in:
6
contrib/Suse/README
Normal file
6
contrib/Suse/README
Normal file
@@ -0,0 +1,6 @@
|
||||
This packaging is now unmaintained in the dnsmasq source: dnsmasq is
|
||||
included in Suse proper, and up-to-date packages are now available
|
||||
from
|
||||
|
||||
ftp://ftp.suse.com/pub/people/ug/
|
||||
|
||||
27
contrib/Suse/README.susefirewall
Normal file
27
contrib/Suse/README.susefirewall
Normal file
@@ -0,0 +1,27 @@
|
||||
This is a patch against SuSEfirewall2-3.1-206 (SuSE 9.x and older)
|
||||
It fixes the depancy from the dns daemon name 'named'
|
||||
After appending the patch, the SuSEfirewall is again able to autodetect
|
||||
the dnsmasq named service.
|
||||
This is a very old bug in the SuSEfirewall script.
|
||||
The SuSE people think the name of the dns server will allways 'named'
|
||||
|
||||
|
||||
--- /sbin/SuSEfirewall2.orig 2004-01-23 13:30:09.000000000 +0100
|
||||
+++ /sbin/SuSEfirewall2 2004-01-23 13:31:56.000000000 +0100
|
||||
@@ -764,7 +764,7 @@
|
||||
echo 'FW_ALLOW_INCOMING_HIGHPORTS_UDP should be set to yes, if you are running a DNS server!'
|
||||
|
||||
test "$FW_SERVICE_AUTODETECT" = yes -o "$FW_SERVICE_AUTODETECT" = dmz -o "$FW_SERVICE_AUTODETECT" = ext && {
|
||||
- test "$FW_SERVICE_DNS" = no -a '!' "$START_NAMED" = no && check_srv named && {
|
||||
+ test "$FW_SERVICE_DNS" = no -a '!' "$START_NAMED" = no && check_srv dnsmasq && {
|
||||
echo -e 'Warning: detected activated named, enabling FW_SERVICE_DNS!
|
||||
You still have to allow tcp/udp port 53 on internal, dmz and/or external.'
|
||||
FW_SERVICE_DNS=$FW_SERVICE_AUTODETECT
|
||||
@@ -878,7 +878,7 @@
|
||||
test -e /etc/resolv.conf || echo "Warning: /etc/resolv.conf not found"
|
||||
# Get ports/IP bindings of NAMED/SQUID
|
||||
test "$FW_SERVICE_DNS" = yes -o "$FW_SERVICE_DNS" = dmz -o "$FW_SERVICE_DNS" = ext -o "$START_NAMED" = yes && DNS_PORT=`$LSOF -i -n -P | \
|
||||
- $AWK -F: '/^named .* UDP / {print $2}'| $GREP -vw 53 | $SORT -un`
|
||||
+ $AWK -F: '/^dnsmasq .* UDP / {print $2}'| $GREP -vw 53 | $SORT -un`
|
||||
test "$FW_SERVICE_SQUID" = yes -o "$FW_SERVICE_SQUID" = dmz -o "$FW_SERVICE_SQUID" = ext -o "$START_SQUID" = yes && SQUID_PORT=`$LSOF -i -n -P | \
|
||||
$AWK -F: '/^squid .* UDP/ {print $2}'| $SORT -un`
|
||||
23
contrib/Suse/dnsmasq-SuSE.patch
Normal file
23
contrib/Suse/dnsmasq-SuSE.patch
Normal file
@@ -0,0 +1,23 @@
|
||||
--- man/dnsmasq.8 2004-08-08 20:57:56.000000000 +0200
|
||||
+++ man/dnsmasq.8 2004-08-12 00:40:01.000000000 +0200
|
||||
@@ -69,7 +69,7 @@
|
||||
.TP
|
||||
.B \-g, --group=<groupname>
|
||||
Specify the group which dnsmasq will run
|
||||
-as. The defaults to "dip", if available, to facilitate access to
|
||||
+as. The defaults to "dialout", if available, to facilitate access to
|
||||
/etc/ppp/resolv.conf which is not normally world readable.
|
||||
.TP
|
||||
.B \-v, --version
|
||||
--- src/config.h 2004-08-11 11:39:18.000000000 +0200
|
||||
+++ src/config.h 2004-08-12 00:40:01.000000000 +0200
|
||||
@@ -44,7 +44,7 @@
|
||||
#endif
|
||||
#define DEFLEASE 3600 /* default lease time, 1 hour */
|
||||
#define CHUSER "nobody"
|
||||
-#define CHGRP "dip"
|
||||
+#define CHGRP "dialout"
|
||||
#define DHCP_SERVER_PORT 67
|
||||
#define DHCP_CLIENT_PORT 68
|
||||
|
||||
|
||||
111
contrib/Suse/dnsmasq-suse.spec
Normal file
111
contrib/Suse/dnsmasq-suse.spec
Normal file
@@ -0,0 +1,111 @@
|
||||
###############################################################################
|
||||
#
|
||||
# General
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
Name: dnsmasq
|
||||
Version: 2.33
|
||||
Release: 1
|
||||
Copyright: GPL
|
||||
Group: Productivity/Networking/DNS/Servers
|
||||
Vendor: Simon Kelley
|
||||
Packager: Simon Kelley
|
||||
URL: http://www.thekelleys.org.uk/dnsmasq
|
||||
Provides: dns_daemon
|
||||
Conflicts: bind bind8 bind9
|
||||
PreReq: %fillup_prereq %insserv_prereq
|
||||
Autoreqprov: on
|
||||
Source0: %{name}-%{version}.tar.bz2
|
||||
BuildRoot: /var/tmp/%{name}-%{version}
|
||||
Summary: A lightweight caching nameserver
|
||||
|
||||
%description
|
||||
Dnsmasq is 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 server and allows machines with DHCP-allocated
|
||||
addresses to appear in the DNS with names configured either in each host or
|
||||
in a central configuration file. Dnsmasq supports static and dynamic DHCP
|
||||
leases and BOOTP for network booting of diskless machines.
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Build
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
patch -p0 <rpm/%{name}-SuSE.patch
|
||||
|
||||
%build
|
||||
%{?suse_update_config:%{suse_update_config -f}}
|
||||
make all-i18n DESTDIR=$RPM_BUILD_ROOT PREFIX=/usr
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Install
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
mkdir -p ${RPM_BUILD_ROOT}/etc/init.d
|
||||
make install-i18n DESTDIR=$RPM_BUILD_ROOT PREFIX=/usr
|
||||
install -o root -g root -m 755 rpm/rc.dnsmasq-suse $RPM_BUILD_ROOT/etc/init.d/dnsmasq
|
||||
install -o root -g root -m 644 dnsmasq.conf.example $RPM_BUILD_ROOT/etc/dnsmasq.conf
|
||||
strip $RPM_BUILD_ROOT/usr/sbin/dnsmasq
|
||||
ln -sf ../../etc/init.d/dnsmasq $RPM_BUILD_ROOT/usr/sbin/rcdnsmasq
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Clean up
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Post-install scriptlet
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
%post
|
||||
%{fillup_and_insserv dnsmasq}
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Post-uninstall scriptlet
|
||||
#
|
||||
# The %postun script executes after the package has been removed. It is the
|
||||
# last chance for a package to clean up after itself.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
%postun
|
||||
%{insserv_cleanup}
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# File list
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%doc CHANGELOG COPYING FAQ doc.html setup.html UPGRADING_to_2.0 rpm/README.susefirewall
|
||||
%doc contrib
|
||||
%config /etc/init.d/dnsmasq
|
||||
%config /etc/dnsmasq.conf
|
||||
/usr/sbin/rcdnsmasq
|
||||
/usr/sbin/dnsmasq
|
||||
/usr/share/locale/*/LC_MESSAGES/*
|
||||
%doc %{_mandir}/man8/dnsmasq.8.gz
|
||||
%doc %{_mandir}/*/man8/dnsmasq.8.gz
|
||||
|
||||
|
||||
79
contrib/Suse/rc.dnsmasq-suse
Normal file
79
contrib/Suse/rc.dnsmasq-suse
Normal file
@@ -0,0 +1,79 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# init.d/dnsmasq
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: dnsmasq
|
||||
# Required-Start: $network $remote_fs $syslog
|
||||
# Required-Stop:
|
||||
# Default-Start: 3 5
|
||||
# Default-Stop:
|
||||
# Description: Starts internet name service masq caching server (DNS)
|
||||
### END INIT INFO
|
||||
|
||||
NAMED_BIN=/usr/sbin/dnsmasq
|
||||
NAMED_PID=/var/run/dnsmasq.pid
|
||||
NAMED_CONF=/etc/dnsmasq.conf
|
||||
|
||||
if [ ! -x $NAMED_BIN ] ; then
|
||||
echo -n "dnsmasq not installed ! "
|
||||
exit 5
|
||||
fi
|
||||
|
||||
. /etc/rc.status
|
||||
rc_reset
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n "Starting name service masq caching server "
|
||||
checkproc -p $NAMED_PID $NAMED_BIN
|
||||
if [ $? -eq 0 ] ; then
|
||||
echo -n "- Warning: dnsmasq already running ! "
|
||||
else
|
||||
[ -e $NAMED_PID ] && echo -n "- Warning: $NAMED_PID exists ! "
|
||||
fi
|
||||
startproc -p $NAMED_PID $NAMED_BIN -u nobody
|
||||
rc_status -v
|
||||
;;
|
||||
stop)
|
||||
echo -n "Shutting name service masq caching server "
|
||||
checkproc -p $NAMED_PID $NAMED_BIN
|
||||
[ $? -ne 0 ] && echo -n "- Warning: dnsmasq not running ! "
|
||||
killproc -p $NAMED_PID -TERM $NAMED_BIN
|
||||
rc_status -v
|
||||
;;
|
||||
try-restart)
|
||||
$0 stop && $0 start
|
||||
rc_status
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
$0 start
|
||||
rc_status
|
||||
;;
|
||||
force-reload)
|
||||
$0 reload
|
||||
rc_status
|
||||
;;
|
||||
reload)
|
||||
echo -n "Reloading name service masq caching server "
|
||||
checkproc -p $NAMED_PID $NAMED_BIN
|
||||
[ $? -ne 0 ] && echo -n "- Warning: dnsmasq not running ! "
|
||||
killproc -p $NAMED_PID -HUP $NAMED_BIN
|
||||
rc_status -v
|
||||
;;
|
||||
status)
|
||||
echo -n "Checking for name service masq caching server "
|
||||
checkproc -p $NAMED_PID $NAMED_BIN
|
||||
rc_status -v
|
||||
;;
|
||||
probe)
|
||||
test $NAMED_CONF -nt $NAMED_PID && echo reload
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
rc_exit
|
||||
|
||||
7
contrib/wrt/Makefile
Normal file
7
contrib/wrt/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
CFLAGS?= -O2
|
||||
|
||||
all: dhcp_release.c
|
||||
$(CC) $(CFLAGS) $(RPM_OPT_FLAGS) -Wall -W dhcp_release.c -o dhcp_release
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o core dhcp_release
|
||||
81
contrib/wrt/README
Normal file
81
contrib/wrt/README
Normal file
@@ -0,0 +1,81 @@
|
||||
This script can be used to implement persistent leases on openWRT, DD-WRT
|
||||
etc. Persistent leases are good: if the lease database is lost on a
|
||||
reboot, then it will eventually be restored as hosts renew their
|
||||
leases. Until a host renews (which may take hours/days) it will
|
||||
not exist in the DNS if dnsmasq's DDNS function is in use.
|
||||
|
||||
*WRT systems remount all non-volatile fileystems read-only after boot,
|
||||
so the normal leasefile will not work. They do, however have NV
|
||||
storage, accessed with the nvram command:
|
||||
|
||||
/usr/lib # nvram
|
||||
usage: nvram [get name] [set name=value] [unset name] [show]
|
||||
|
||||
The principle is that leases are kept in NV variable with data
|
||||
corresponding to the line in a leasefile:
|
||||
|
||||
dnsmasq_lease_192.168.1.56=3600 00:41:4a:05:80:74 192.168.1.56 * *
|
||||
|
||||
By giving dnsmasq the leasefile-ro command, it no longer creates or writes a
|
||||
leasefile; responsibility for maintaining the lease database transfers
|
||||
to the lease change script. At startup, in leasefile-ro mode,
|
||||
dnsmasq will run
|
||||
|
||||
"<lease_change_script> init"
|
||||
|
||||
and read whatever that command spits out, expecting it to
|
||||
be in dnsmasq leasefile format.
|
||||
|
||||
So the lease change script, given "init" as argv[1] will
|
||||
suck existing leases out of the NVRAM and emit them from
|
||||
stdout in the correct format.
|
||||
|
||||
The second part of the problem is keeping the NVRAM up-to-date: this
|
||||
is done by the lease-change script which dnsmasq runs when a lease is
|
||||
updated. When it is called with argv[1] as "old", "add", or "del"
|
||||
it updates the relevant nvram entry.
|
||||
|
||||
So, dnsmasq should be run as :
|
||||
|
||||
dnsmasq --leasefile-ro --dhcp-script=/path/to/lease_update.sh
|
||||
|
||||
or the same flags added to /etc/dnsmasq.conf
|
||||
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
This needs dnsmasq-2.33 or later to work.
|
||||
|
||||
This technique will work with, or without, compilation with
|
||||
HAVE_BROKEN_RTC. Compiling with HAVE_BROKEN_RTC is
|
||||
_highly_recommended_ for this application since is avoids problems
|
||||
with the system clock being warped by NTP, and it vastly reduces the
|
||||
number of writes to the NVRAM. With HAVE_BROKEN_RTC, NVRAM is updated
|
||||
only when a lease is created or destroyed; without it, a write occurs
|
||||
every time a lease is renewed.
|
||||
|
||||
It probably makes sense to restrict the number of active DHCP leases
|
||||
to an appropriate number using dhcp-lease-max. On a new DD_WRT system,
|
||||
there are about 10K bytes free in the NVRAM. Each lease record is
|
||||
about 100 bytes, so restricting the number of leases to 50 will limit
|
||||
use to half that. (The default limit in the distributed source is 150)
|
||||
|
||||
Any UI script which reads the dnsmasq leasefile will have to be
|
||||
ammended, probably by changing it to read the output of
|
||||
`lease_update init` instead.
|
||||
|
||||
|
||||
Thanks:
|
||||
|
||||
To Steve Horbachuk for checks on the script and debugging beyond the
|
||||
call of duty.
|
||||
|
||||
|
||||
Simon Kelley
|
||||
Fri Jul 28 11:51:13 BST 2006
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
184
contrib/wrt/dhcp_release.c
Normal file
184
contrib/wrt/dhcp_release.c
Normal file
@@ -0,0 +1,184 @@
|
||||
/* Copyright (c) 2006 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.
|
||||
*/
|
||||
|
||||
/* dhcp_release <interface> <address> <MAC address> <client_id>
|
||||
MUST be run as root - will fail otherwise. */
|
||||
|
||||
/* Send a DHCPRELEASE message via the specified interface
|
||||
to tell the local DHCP server to delete a particular lease.
|
||||
|
||||
The interface argument is the interface in which a DHCP
|
||||
request _would_ be received if it was coming from the client,
|
||||
rather than being faked up here.
|
||||
|
||||
The address argument is a dotted-quad IP addresses and mandatory.
|
||||
|
||||
The MAC address is colon separated hex, and is mandatory. It may be
|
||||
prefixed by an address-type byte followed by -, eg
|
||||
|
||||
10-11:22:33:44:55:66
|
||||
|
||||
but if the address-type byte is missing it is assumed to be 1, the type
|
||||
for ethernet. This encoding is the one used in dnsmasq lease files.
|
||||
|
||||
The client-id is optional. If it is "*" then it treated as being missing.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#define DHCP_CHADDR_MAX 16
|
||||
#define BOOTREQUEST 1
|
||||
#define DHCP_COOKIE 0x63825363
|
||||
#define OPTION_SERVER_IDENTIFIER 54
|
||||
#define OPTION_CLIENT_ID 61
|
||||
#define OPTION_MESSAGE_TYPE 53
|
||||
#define OPTION_END 255
|
||||
#define DHCPRELEASE 7
|
||||
#define DHCP_SERVER_PORT 67
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
|
||||
struct dhcp_packet {
|
||||
u8 op, htype, hlen, hops;
|
||||
u32 xid;
|
||||
u16 secs, flags;
|
||||
struct in_addr ciaddr, yiaddr, siaddr, giaddr;
|
||||
u8 chaddr[DHCP_CHADDR_MAX], sname[64], file[128];
|
||||
u32 cookie;
|
||||
unsigned char options[308];
|
||||
};
|
||||
|
||||
static int parse_hex(char *in, unsigned char *out, int maxlen, int *mac_type)
|
||||
{
|
||||
int i = 0;
|
||||
char *r;
|
||||
|
||||
if (mac_type)
|
||||
*mac_type = 0;
|
||||
|
||||
while (maxlen == -1 || i < maxlen)
|
||||
{
|
||||
for (r = in; *r != 0 && *r != ':' && *r != '-'; r++);
|
||||
if (*r == 0)
|
||||
maxlen = i;
|
||||
|
||||
if (r != in )
|
||||
{
|
||||
if (*r == '-' && i == 0 && mac_type)
|
||||
{
|
||||
*r = 0;
|
||||
*mac_type = strtol(in, NULL, 16);
|
||||
mac_type = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
*r = 0;
|
||||
out[i] = strtol(in, NULL, 16);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
in = r+1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct in_addr server, lease;
|
||||
int mac_type;
|
||||
struct dhcp_packet packet;
|
||||
unsigned char *p = packet.options;
|
||||
struct sockaddr_in dest;
|
||||
struct ifreq ifr;
|
||||
int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
if (argc < 4 || argc > 5)
|
||||
{
|
||||
fprintf(stderr, "usage: dhcp_release <interface> <addr> <mac> [<client_id>]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("cannot create socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* This voodoo fakes up a packet coming from the correct interface, which really matters for
|
||||
a DHCP server */
|
||||
strcpy(ifr.ifr_name, argv[1]);
|
||||
ifr.ifr_addr.sa_family = AF_INET;
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr) == -1 || setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) == -1)
|
||||
{
|
||||
perror("cannot setup interface");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
server = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr;
|
||||
lease.s_addr = inet_addr(argv[2]);
|
||||
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
packet.hlen = parse_hex(argv[3], packet.chaddr, DHCP_CHADDR_MAX, &mac_type);
|
||||
if (mac_type == 0)
|
||||
packet.htype = ARPHRD_ETHER;
|
||||
else
|
||||
packet.htype = mac_type;
|
||||
|
||||
packet.op = BOOTREQUEST;
|
||||
packet.ciaddr = lease;
|
||||
packet.cookie = htonl(DHCP_COOKIE);
|
||||
|
||||
*(p++) = OPTION_MESSAGE_TYPE;
|
||||
*(p++) = 1;
|
||||
*(p++) = DHCPRELEASE;
|
||||
|
||||
*(p++) = OPTION_SERVER_IDENTIFIER;
|
||||
*(p++) = sizeof(server);
|
||||
memcpy(p, &server, sizeof(server));
|
||||
p += sizeof(server);
|
||||
|
||||
if (argc == 5 && strcmp(argv[4], "*") != 0)
|
||||
{
|
||||
unsigned int clid_len = parse_hex(argv[4], p+2, 255, NULL);
|
||||
*(p++) = OPTION_CLIENT_ID;
|
||||
*(p++) = clid_len;
|
||||
p += clid_len;
|
||||
}
|
||||
|
||||
*(p++) = OPTION_END;
|
||||
|
||||
dest.sin_family = AF_INET;
|
||||
dest.sin_port = ntohs(DHCP_SERVER_PORT);
|
||||
dest.sin_addr = server;
|
||||
|
||||
if (sendto(fd, &packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&dest, sizeof(dest)) == 1)
|
||||
{
|
||||
perror("sendto failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
57
contrib/wrt/lease_update.sh
Executable file
57
contrib/wrt/lease_update.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2006 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.
|
||||
|
||||
|
||||
# if $1 is add del or old, this is a dnsmasq-called lease-change
|
||||
# script, update the nvram database. if $1 is init, emit a
|
||||
# dnsmasq-format lease file to stdout representing the current state of the
|
||||
# database, this is called by dnsmasq at startup.
|
||||
|
||||
NVRAM=/usr/sbin/nvram
|
||||
PREFIX=dnsmasq_lease_
|
||||
|
||||
# Arguments.
|
||||
# $1 is action (add, del, old)
|
||||
# $2 is MAC
|
||||
# $3 is address
|
||||
# $4 is hostname (optional, may be unset)
|
||||
|
||||
# env.
|
||||
# DNSMASQ_LEASE_LENGTH or DNSMASQ_LEASE_EXPIRES (which depends on HAVE_BROKEN_RTC)
|
||||
# DNSMASQ_CLIENT_ID (optional, may be unset)
|
||||
|
||||
# File.
|
||||
# length|expires MAC addr hostname|* CLID|*
|
||||
|
||||
# Primary key is address.
|
||||
|
||||
NVRAM=/usr/sbin/nvram
|
||||
PREFIX=dnsmasq_lease_
|
||||
|
||||
if [ ${1} = init ] ; then
|
||||
${NVRAM} show | sed -n -e "/^${PREFIX}.*/ s/^.*=//p"
|
||||
else
|
||||
if [ ${1} = del ] ; then
|
||||
${NVRAM} unset ${PREFIX}${3}
|
||||
fi
|
||||
|
||||
if [ ${1} = old ] || [ ${1} = add ] ; then
|
||||
${NVRAM} set ${PREFIX}${3}="${DNSMASQ_LEASE_LENGTH:-}${DNSMASQ_LEASE_EXPIRES:-} ${2} ${3} ${4:-*} ${DNSMASQ_CLIENT_ID:-*}"
|
||||
fi
|
||||
${NVRAM} commit
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user