1 | 1 |
#
|
2 | 2 |
# If we have an unicast .local domain, we immediately disable avahi to avoid
|
3 | 3 |
# conflicts with the multicast IP4LL .local domain
|
4 | |
DISABLE_TAG_DIR="/var/run/avahi-daemon/"
|
5 | |
DISABLE_TAG="$DISABLE_TAG_DIR/disabled-for-unicast-local"
|
|
4 |
|
|
5 |
RUNDIR="/var/run/avahi-daemon/"
|
|
6 |
DISABLE_TAG="$RUNDIR/disabled-for-unicast-local"
|
|
7 |
NS_CACHE="$RUNDIR/checked_nameservers"
|
6 | 8 |
|
7 | 9 |
AVAHI_DAEMON_DETECT_LOCAL=1
|
8 | 10 |
|
|
12 | 14 |
exit 0
|
13 | 15 |
fi
|
14 | 16 |
|
|
17 |
ensure_rundir() {
|
|
18 |
if [ ! -d ${RUNDIR} ] ; then
|
|
19 |
mkdir -m 0755 -p ${RUNDIR}
|
|
20 |
chown avahi:avahi ${RUNDIR}
|
|
21 |
fi
|
|
22 |
}
|
15 | 23 |
|
16 | |
dns_has_local() {
|
17 | |
# If there are no nameserver entries in resolv.conf there are no unicast
|
18 | |
# .local domains :)
|
|
24 |
dns_reachable() {
|
|
25 |
# If there are no nameserver entries in resolv.conf there is no dns reachable
|
19 | 26 |
$(grep -q nameserver /etc/resolv.conf) || return 1;
|
20 | 27 |
|
21 | 28 |
# If there is no local nameserver and no we have no global ip addresses
|
22 | |
# then there is no need to query the nameservers
|
|
29 |
# then we can't reach any nameservers
|
23 | 30 |
if ! $(egrep -q "nameserver 127.0.0.1|::1" /etc/resolv.conf); then
|
24 | 31 |
# Get addresses of all running interfaces
|
25 | 32 |
ADDRS=$(LC_ALL=C ifconfig | grep ' addr:')
|
|
30 | 37 |
fi
|
31 | 38 |
fi
|
32 | 39 |
|
|
40 |
return 0
|
|
41 |
}
|
|
42 |
|
|
43 |
dns_has_local() {
|
|
44 |
# Some magic to do tests
|
|
45 |
if [ -n ${FAKE_HOST_RETURN} ] ; then
|
|
46 |
if [ "${FAKE_HOST_RETURN}" = "true" ]; then
|
|
47 |
return 0;
|
|
48 |
else
|
|
49 |
return 1;
|
|
50 |
fi
|
|
51 |
fi
|
|
52 |
|
33 | 53 |
OUT=`LC_ALL=C host -t soa local. 2>&1`
|
34 | |
if [ $? -eq 0 ] && echo "$OUT" | egrep -vq 'has no|not found'; then
|
35 | |
return 0
|
|
54 |
if [ $? -eq 0 ] ; then
|
|
55 |
if echo "$OUT" | egrep -vq 'has no|not found'; then
|
|
56 |
return 0
|
|
57 |
fi
|
|
58 |
else
|
|
59 |
# Checking the dns servers failed. Assuming no .local unicast dns, but
|
|
60 |
# remove the nameserver cache so we recheck the next time we're triggered
|
|
61 |
rm -f ${NS_CACHE}
|
36 | 62 |
fi
|
37 | 63 |
return 1
|
38 | 64 |
}
|
39 | 65 |
|
40 | |
if dns_has_local ; then
|
41 | |
if [ -x /etc/init.d/avahi-daemon ]; then
|
|
66 |
dns_needs_check() {
|
|
67 |
TMP_CACHE="${NS_CACHE}.$$"
|
|
68 |
RET=0
|
|
69 |
|
|
70 |
ensure_rundir
|
|
71 |
cat /etc/resolv.conf | grep "nameserver" | sort > ${TMP_CACHE} || return 0
|
|
72 |
|
|
73 |
if [ -e ${NS_CACHE} ]; then
|
|
74 |
DIFFERENCE=$(diff -w ${NS_CACHE} ${TMP_CACHE})
|
|
75 |
echo "${DIFFERENCE}" | grep -q '^>'
|
|
76 |
ADDED=$?
|
|
77 |
echo "${DIFFERENCE}" | grep -q '^<'
|
|
78 |
REMOVED=$?
|
|
79 |
echo "${DIFFERENCE}"
|
|
80 |
# Avahi was disabled and no servers were removed, no need to recheck
|
|
81 |
[ -e ${DISABLE_TAG} ] && [ ${REMOVED} -ne 0 ] && RET=1
|
|
82 |
# Avahi was enabled and no servers were added, no need to recheck
|
|
83 |
[ ! -e ${DISABLE_TAG} ] && [ ${ADDED} -ne 0 ] && RET=1
|
|
84 |
fi
|
|
85 |
|
|
86 |
mv ${TMP_CACHE} ${NS_CACHE}
|
|
87 |
return ${RET};
|
|
88 |
}
|
|
89 |
|
|
90 |
|
|
91 |
enable_avahi () {
|
|
92 |
# no unicast .local conflict, so remove the tag and start avahi again
|
|
93 |
if [ -e ${DISABLE_TAG} ]; then
|
|
94 |
rm -f ${DISABLE_TAG}
|
|
95 |
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
|
96 |
invoke-rc.d avahi-daemon start || true
|
|
97 |
else
|
|
98 |
if [ -x "/etc/init.d/avahi-daemon" ]; then
|
|
99 |
/etc/init.d/avahi-daemon start || true
|
|
100 |
fi
|
|
101 |
fi
|
|
102 |
fi
|
|
103 |
}
|
|
104 |
|
|
105 |
disable_avahi () {
|
|
106 |
[ -e ${DISABLE_TAG} ] && return
|
|
107 |
|
|
108 |
if [ -x /etc/init.d/avahi-daemon ]; then
|
|
109 |
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
|
|
110 |
invoke-rc.d --force avahi-daemon stop || true
|
|
111 |
else
|
|
112 |
if [ -x "/etc/init.d/avahi-daemon" ]; then
|
42 | 113 |
/etc/init.d/avahi-daemon stop || true
|
43 | |
if [ -x /usr/bin/logger ]; then
|
44 | |
logger -p daemon.warning -t avahi <<EOF
|
|
114 |
fi
|
|
115 |
fi
|
|
116 |
if [ -x /usr/bin/logger ]; then
|
|
117 |
logger -p daemon.warning -t avahi <<EOF
|
45 | 118 |
Avahi detected that your currently configured local DNS server serves
|
46 | 119 |
a domain .local. This is inherently incompatible with Avahi and thus
|
47 | 120 |
Avahi disabled itself. If you want to use Avahi in this network, please
|
|
49 | 122 |
since .local should be used exclusively for Zeroconf technology.
|
50 | 123 |
For more information, see http://avahi.org/wiki/AvahiAndUnicastDotLocal
|
51 | 124 |
EOF
|
52 | |
fi
|
53 | 125 |
fi
|
54 | |
if [ ! -d ${DISABLE_TAG_DIR} ] ; then
|
55 | |
mkdir -m 0755 -p ${DISABLE_TAG_DIR}
|
56 | |
chown avahi:avahi ${DISABLE_TAG_DIR}
|
57 | |
fi
|
58 | |
touch ${DISABLE_TAG}
|
|
126 |
fi
|
|
127 |
ensure_rundir
|
|
128 |
touch ${DISABLE_TAG}
|
|
129 |
}
|
|
130 |
|
|
131 |
if ! dns_reachable ; then
|
|
132 |
# No unicast dns server reachable, so enable avahi
|
|
133 |
enable_avahi
|
|
134 |
# And blow away the dns cache, so we force a recheck when the interface comes
|
|
135 |
# up again
|
|
136 |
rm -f ${NS_CACHE}
|
|
137 |
exit 0
|
|
138 |
fi
|
|
139 |
|
|
140 |
# Check if the dns needs checking..
|
|
141 |
dns_needs_check || exit 0
|
|
142 |
|
|
143 |
if dns_has_local ; then
|
|
144 |
# .local from dns server, disabling avahi
|
|
145 |
disable_avahi
|
59 | 146 |
else
|
60 | |
# no unicast .local conflict, so remove the tag and start avahi again
|
61 | |
if [ -e ${DISABLE_TAG} ]; then
|
62 | |
rm -f ${DISABLE_TAG}
|
63 | |
if [ -x /etc/init.d/avahi-daemon ]; then
|
64 | |
/etc/init.d/avahi-daemon start || true
|
65 | |
fi
|
66 | |
fi
|
|
147 |
# no .local from dns server, enablign avahi
|
|
148 |
enable_avahi
|
67 | 149 |
fi
|
68 | 150 |
|
69 | 151 |
exit 0
|