summaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-support/dnsmasq
diff options
context:
space:
mode:
authorJens Rehsack <rehsack@gmail.com>2016-02-28 13:34:22 +0100
committerJoe MacDonald <joe_macdonald@mentor.com>2016-04-01 12:05:27 -0400
commit2497cf2960537152427c99629b2af412787eb6c2 (patch)
tree2f3559f93ffa4b6bf0fde2f5c05ac720ce12fd6a /meta-networking/recipes-support/dnsmasq
parente6c6a5dfea7c452e0549194131ea3367a3e0459d (diff)
downloadmeta-openembedded-2497cf2960537152427c99629b2af412787eb6c2.tar.gz
dnsmasq: steal resolvconf support from Ubuntu
Add support for resolvconf integration as done in Ubuntu. This implies updates of start-scripts, resolvconf plugin (on nameserver update ...), populate-volatiles control file for saved nameserver list. Signed-off-by: Jens Rehsack <sno@netbsd.org> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
Diffstat (limited to 'meta-networking/recipes-support/dnsmasq')
-rw-r--r--meta-networking/recipes-support/dnsmasq/dnsmasq.inc10
-rw-r--r--meta-networking/recipes-support/dnsmasq/files/99_dnsmasq1
-rwxr-xr-xmeta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf84
-rw-r--r--meta-networking/recipes-support/dnsmasq/files/dnsmasq.service7
-rw-r--r--meta-networking/recipes-support/dnsmasq/files/init69
5 files changed, 167 insertions, 4 deletions
diff --git a/meta-networking/recipes-support/dnsmasq/dnsmasq.inc b/meta-networking/recipes-support/dnsmasq/dnsmasq.inc
index 7fec60678..622e63067 100644
--- a/meta-networking/recipes-support/dnsmasq/dnsmasq.inc
+++ b/meta-networking/recipes-support/dnsmasq/dnsmasq.inc
@@ -23,6 +23,7 @@ PACKAGECONFIG[dbus] = ",,dbus"
23PACKAGECONFIG[idn] = ",,libidn" 23PACKAGECONFIG[idn] = ",,libidn"
24PACKAGECONFIG[conntrack] = ",,libnetfilter-conntrack" 24PACKAGECONFIG[conntrack] = ",,libnetfilter-conntrack"
25PACKAGECONFIG[lua] = ",,lua" 25PACKAGECONFIG[lua] = ",,lua"
26PACKAGECONFIG[resolvconf] = ",,,resolvconf"
26EXTRA_OEMAKE = "\ 27EXTRA_OEMAKE = "\
27 'COPTS=${@base_contains('PACKAGECONFIG', 'dbus', '-DHAVE_DBUS', '', d)} \ 28 'COPTS=${@base_contains('PACKAGECONFIG', 'dbus', '-DHAVE_DBUS', '', d)} \
28 ${@base_contains('PACKAGECONFIG', 'idn', '-DHAVE_IDN', '', d)} \ 29 ${@base_contains('PACKAGECONFIG', 'idn', '-DHAVE_IDN', '', d)} \
@@ -32,6 +33,8 @@ EXTRA_OEMAKE = "\
32 'LDFLAGS=${LDFLAGS}' \ 33 'LDFLAGS=${LDFLAGS}' \
33" 34"
34 35
36SRC_URI += "${@bb.utils.contains('PACKAGECONFIG', 'resolvconf', 'file://dnsmasq.resolvconf file://99_dnsmasq', '', d)}"
37
35do_compile_append() { 38do_compile_append() {
36 # build dhcp_release 39 # build dhcp_release
37 cd ${S}/contrib/wrt 40 cd ${S}/contrib/wrt
@@ -56,6 +59,13 @@ do_install () {
56 install -d ${D}${sysconfdir}/dbus-1/system.d 59 install -d ${D}${sysconfdir}/dbus-1/system.d
57 install -m 644 dbus/dnsmasq.conf ${D}${sysconfdir}/dbus-1/system.d/ 60 install -m 644 dbus/dnsmasq.conf ${D}${sysconfdir}/dbus-1/system.d/
58 fi 61 fi
62 if [ "${@base_contains('PACKAGECONFIG', 'resolvconf', 'resolvconf', '', d)}" != "" ]; then
63 install -d ${D}${sysconfdir}/resolvconf/update.d/
64 install -m 0755 ${WORKDIR}/dnsmasq.resolvconf ${D}${sysconfdir}/resolvconf/update.d/dnsmasq
65
66 install -d ${D}${sysconfdir}/default/volatiles
67 install -m 0644 ${WORKDIR}/99_dnsmasq ${D}${sysconfdir}/default/volatiles
68 fi
59} 69}
60 70
61CONFFILES_${PN} = "${sysconfdir}/dnsmasq.conf" 71CONFFILES_${PN} = "${sysconfdir}/dnsmasq.conf"
diff --git a/meta-networking/recipes-support/dnsmasq/files/99_dnsmasq b/meta-networking/recipes-support/dnsmasq/files/99_dnsmasq
new file mode 100644
index 000000000..f52ce4e8f
--- /dev/null
+++ b/meta-networking/recipes-support/dnsmasq/files/99_dnsmasq
@@ -0,0 +1 @@
d root root 0755 /run/dnsmasq none
diff --git a/meta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf
new file mode 100755
index 000000000..06cd25cec
--- /dev/null
+++ b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf
@@ -0,0 +1,84 @@
1#!/bin/sh
2#
3# Script to update the resolver list for dnsmasq
4#
5# N.B. Resolvconf may run us even if dnsmasq is not (yet) running.
6# If dnsmasq is installed then we go ahead and update the resolver list
7# in case dnsmasq is started later.
8#
9# Assumption: On entry, PWD contains the resolv.conf-type files.
10#
11# This file is part of the dnsmasq package.
12#
13
14set -e
15
16RUN_DIR="/run/dnsmasq"
17RSLVRLIST_FILE="${RUN_DIR}/resolv.conf"
18TMP_FILE="${RSLVRLIST_FILE}_new.$$"
19MY_NAME_FOR_RESOLVCONF="dnsmasq"
20
21[ -x /usr/bin/dnsmasq ] || exit 0
22[ -x /lib/resolvconf/list-records ] || exit 1
23
24PATH=/bin:/sbin
25
26report_err() { echo "$0: Error: $*" >&2 ; }
27
28# Stores arguments (minus duplicates) in RSLT, separated by spaces
29# Doesn't work properly if an argument itself contains whitespace
30uniquify()
31{
32 RSLT=""
33 while [ "$1" ] ; do
34 for E in $RSLT ; do
35 [ "$1" = "$E" ] && { shift ; continue 2 ; }
36 done
37 RSLT="${RSLT:+$RSLT }$1"
38 shift
39 done
40}
41
42if [ ! -d "$RUN_DIR" ] && ! mkdir --parents --mode=0755 "$RUN_DIR" ; then
43 report_err "Failed trying to create directory $RUN_DIR"
44 exit 1
45fi
46
47RSLVCNFFILES=""
48for F in $(/lib/resolvconf/list-records --after "lo.$MY_NAME_FOR_RESOLVCONF") ; do
49 case "$F" in
50 "lo.$MY_NAME_FOR_RESOLVCONF")
51 # Omit own record
52 ;;
53 lo.*)
54 # Include no more records after one for a local nameserver
55 RSLVCNFFILES="${RSLVCNFFILES:+$RSLVCNFFILES }$F"
56 break
57 ;;
58 *)
59 RSLVCNFFILES="${RSLVCNFFILES:+$RSLVCNFFILES }$F"
60 ;;
61 esac
62done
63
64NMSRVRS=""
65if [ "$RSLVCNFFILES" ] ; then
66 uniquify $(sed -n -e 's/^[[:space:]]*nameserver[[:space:]]\+//p' $RSLVCNFFILES)
67 NMSRVRS="$RSLT"
68fi
69
70# Dnsmasq uses the mtime of $RSLVRLIST_FILE, with a resolution of one second,
71# to detect changes in the file. This means that if a resolvconf update occurs
72# within one second of the previous one then dnsmasq may fail to notice the
73# more recent change. To work around this problem we sleep one second here
74# if necessary in order to ensure that the new mtime is different.
75if [ -f "$RSLVRLIST_FILE" ] && [ "$(stat -c %X "$RSLVRLIST_FILE")" = "$(date +%s)" ] ; then
76 sleep 1
77fi
78
79clean_up() { rm -f "$TMP_FILE" ; }
80trap clean_up EXIT
81: >| "$TMP_FILE"
82for N in $NMSRVRS ; do echo "nameserver $N" >> "$TMP_FILE" ; done
83mv -f "$TMP_FILE" "$RSLVRLIST_FILE"
84
diff --git a/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service
index 549e15e2b..c3637e142 100644
--- a/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service
+++ b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service
@@ -5,8 +5,11 @@ After=network.target
5[Service] 5[Service]
6Type=forking 6Type=forking
7PIDFile=/run/dnsmasq.pid 7PIDFile=/run/dnsmasq.pid
8ExecStart=/usr/bin/dnsmasq -x /run/dnsmasq.pid 8ExecStartPre=/usr/sbin/dnsmasq --test
9ExecReload=/bin/kill -HUP $(/bin/cat /run/dnsmasq.pid) 9ExecStart=/etc/init.d/dnsmasq systemd-exec
10ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf
11ExecStopPre=/etc/init.d/dnsmasq systemd-stop-resolvconf
12ExecReload=/bin/kill -HUP $MAINPID
10 13
11[Install] 14[Install]
12WantedBy=multi-user.target 15WantedBy=multi-user.target
diff --git a/meta-networking/recipes-support/dnsmasq/files/init b/meta-networking/recipes-support/dnsmasq/files/init
index d1aa9e517..51c95dfed 100644
--- a/meta-networking/recipes-support/dnsmasq/files/init
+++ b/meta-networking/recipes-support/dnsmasq/files/init
@@ -8,15 +8,68 @@ test -f $DAEMON || exit 0
8 8
9set -e 9set -e
10 10
11if [ -r /etc/default/$NAME ]
12then
13 . /etc/default/$NAME
14fi
15
16DNSMASQ_CONF="/etc/dnsmasq.conf"
17test "/etc/dnsmasq.d/*" != '/etc/dnsmasq.d/*' && DNSMASQ_CONF="${DNSMASQ_CONF} /etc/dnsmasq.d/*"
18
19test -z "${PIDFILE}" && PIFILE="/run/dnsmasq.pid"
20
21if [ -z "$IGNORE_RESOLVCONF" ]
22then
23 egrep -h -q '^no-resolv' ${DNSMASQ_CONF} && IGNORE_RESOLVCONF="yes"
24fi
25
26# RESOLV_CONF:
27# If the resolvconf package is installed then use the resolv conf file
28# that it provides as the default. Otherwise use /etc/resolv.conf as
29# the default.
30#
31# If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit
32# filename is set there then this inhibits the use of the resolvconf-provided
33# information.
34#
35# Note that if the resolvconf package is installed it is not possible to
36# override it just by configuration in /etc/dnsmasq.conf, it is necessary
37# to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq.
38
39test -z "$RESOLV_CONF" -a "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf && \
40 RESOLV_CONF=/run/dnsmasq/resolv.conf
41
42start_resolvconf()
43{
44 if [ "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf ]
45 then
46 echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME
47 fi
48 :
49}
50
51stop_resolvconf()
52{
53 if [ "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf ]
54 then
55 /sbin/resolvconf -d lo.$NAME
56 fi
57 :
58}
59
11case "$1" in 60case "$1" in
12 start) 61 start)
13 echo -n "starting $DESC: $NAME... " 62 echo -n "starting $DESC: $NAME... "
14 test -d /var/lib/misc/ || mkdir /var/lib/misc/ 63 test -d /var/lib/misc/ || mkdir /var/lib/misc/
15 start-stop-daemon -S -x $DAEMON -- $ARGS 64 start-stop-daemon -S -x $DAEMON -- $ARGS \
65 ${RESOLV_CONF:+ -r $RESOLV_CONF} \
66 ${PIDFILE:+ -x $PIDFILE}
67 test $? -eq 0 && start_resolvconf
16 echo "done." 68 echo "done."
17 ;; 69 ;;
18 stop) 70 stop)
19 echo -n "stopping $DESC: $NAME... " 71 echo -n "stopping $DESC: $NAME... "
72 stop_resolvconf
20 start-stop-daemon -K -x $DAEMON 73 start-stop-daemon -K -x $DAEMON
21 echo "done." 74 echo "done."
22 ;; 75 ;;
@@ -25,7 +78,7 @@ case "$1" in
25 start-stop-daemon -q -K -t -x $DAEMON 78 start-stop-daemon -q -K -t -x $DAEMON
26 RET=$? 79 RET=$?
27 if [ "$RET" = "0" ]; then 80 if [ "$RET" = "0" ]; then
28 PID=`cat /var/run/dnsmasq.pid` 81 PID=`cat ${PIDFILE}`
29 echo "($PID) is running" 82 echo "($PID) is running"
30 else 83 else
31 echo "is not running" 84 echo "is not running"
@@ -43,6 +96,18 @@ case "$1" in
43 killall -HUP $(basename ${DAEMON}) 96 killall -HUP $(basename ${DAEMON})
44 echo "done." 97 echo "done."
45 ;; 98 ;;
99 systemd-start-resolvconf)
100 start_resolvconf
101 ;;
102 systemd-stop-resolvconf)
103 stop_resolvconf
104 ;;
105 systemd-exec)
106 test -d /var/lib/misc/ || mkdir /var/lib/misc/
107 exec $DAEMON --keep-in-foreground $ARGS \
108 ${RESOLV_CONF:+ -r $RESOLV_CONF} \
109 ${PIDFILE:+ -x $PIDFILE}
110 ;;
46 *) 111 *)
47 echo "Usage: $0 {start|stop|status|restart|reload}" 112 echo "Usage: $0 {start|stop|status|restart|reload}"
48 exit 1 113 exit 1