aboutsummaryrefslogtreecommitdiffstats
path: root/dhcpcd-hooks
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:11 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:11 -0800
commit4c5a5fb53bccceff331bae70f748bf9b4609fe0a (patch)
treed6ae69d0d3f4a4d760a3254ec326bca4a8afacfe /dhcpcd-hooks
parente95877ecfa1170d77b1ec1f66752725cdda01b64 (diff)
downloadexternal_dhcpcd-4c5a5fb53bccceff331bae70f748bf9b4609fe0a.zip
external_dhcpcd-4c5a5fb53bccceff331bae70f748bf9b4609fe0a.tar.gz
external_dhcpcd-4c5a5fb53bccceff331bae70f748bf9b4609fe0a.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'dhcpcd-hooks')
-rw-r--r--dhcpcd-hooks/01-test2
-rw-r--r--dhcpcd-hooks/20-resolv.conf87
-rw-r--r--dhcpcd-hooks/29-lookup-hostname3
-rw-r--r--dhcpcd-hooks/30-hostname15
-rw-r--r--dhcpcd-hooks/50-ntp.conf87
-rw-r--r--dhcpcd-hooks/50-yp.conf1
-rw-r--r--dhcpcd-hooks/90-NetworkManager11
-rw-r--r--dhcpcd-hooks/95-configured6
-rw-r--r--dhcpcd-hooks/Makefile4
9 files changed, 165 insertions, 51 deletions
diff --git a/dhcpcd-hooks/01-test b/dhcpcd-hooks/01-test
index d3ca40d..609b3a1 100644
--- a/dhcpcd-hooks/01-test
+++ b/dhcpcd-hooks/01-test
@@ -3,5 +3,5 @@
case ${reason} in
TEST) set | grep "^\(interface\|metric\|pid\|reason\|skip_hooks\)=" | sort
set | grep "^\(new_\|old_\)" | sort
- ;;
+ ;;
esac
diff --git a/dhcpcd-hooks/20-resolv.conf b/dhcpcd-hooks/20-resolv.conf
index 437c116..e757ddf 100644
--- a/dhcpcd-hooks/20-resolv.conf
+++ b/dhcpcd-hooks/20-resolv.conf
@@ -1,14 +1,71 @@
# Generate /etc/resolv.conf
# Support resolvconf(8) if available
+# We can merge other dhcpcd resolv.conf files into one like resolvconf,
+# but resolvconf is preferred as other applications like VPN clients
+# can readily hook into it.
+# Also, resolvconf can configure local nameservers such as bind
+# or dnsmasq. This is important as the libc resolver isn't that powerful.
-make_resolv_conf()
+resolv_conf_dir="${state_dir}/resolv.conf"
+
+build_resolv_conf()
+{
+ local cf="/etc/resolv.conf.${interface}"
+ local interfaces= header= search= srvs= servers= x=
+
+ # Build a list of interfaces
+ interfaces=$(list_interfaces "${resolv_conf_dir}")
+
+ # Build the resolv.conf
+ if [ -n "${interfaces}" ]; then
+ # Build the header
+ for x in ${interfaces}; do
+ header="${header}${header:+, }${x}"
+ done
+
+ # Build the search list
+ search=$(cd "${resolv_conf_dir}"; \
+ key_get_value "search " ${interfaces})
+ [ -n "${search}" ] && search="search $(uniqify ${search})\n"
+
+ # Build the nameserver list
+ srvs=$(cd "${resolv_conf_dir}"; \
+ key_get_value "nameserver " ${interfaces})
+ for x in $(uniqify ${srvs}); do
+ servers="${servers}nameserver ${x}\n"
+ done
+ fi
+ header="${signature_base}${header:+ ${from} }${header}"
+
+ # Assemble resolv.conf using our head and tail files
+ [ -f "${cf}" ] && rm -f "${cf}"
+ echo "${header}" > "${cf}"
+ if [ -f /etc/resolv.conf.head ]; then
+ cat /etc/resolv.conf.head >> "${cf}"
+ else
+ echo "# /etc/resolv.conf.head can replace this line" >> "${cf}"
+ fi
+ printf "${search}${servers}" >> "${cf}"
+ if [ -f /etc/resolv.conf.tail ]; then
+ cat /etc/resolv.conf.tail >> "${cf}"
+ else
+ echo "# /etc/resolv.conf.tail can replace this line" >> "${cf}"
+ fi
+ mv -f "${cf}" /etc/resolv.conf
+}
+
+add_resolv_conf()
{
+ local x= conf="${signature}\n"
+
+ # If we don't have any configuration, remove it
if [ -z "${new_domain_name_servers}" -a \
-z "${new_domain_name}" -a \
-z "${new_domain_search}" ]; then
- return 0
+ remove_resolv_conf
+ return $?
fi
- local x= conf="${signature}\n"
+
if [ -n "${new_domain_search}" ]; then
conf="${conf}search ${new_domain_search}\n"
elif [ -n "${new_domain_name}" ]; then
@@ -19,22 +76,32 @@ make_resolv_conf()
done
if type resolvconf >/dev/null 2>&1; then
printf "${conf}" | resolvconf -a "${interface}"
- else
- save_conf /etc/resolv.conf
- printf "${conf}" > /etc/resolv.conf
+ return $?
+ fi
+
+ if [ -e "${resolv_conf_dir}/${interface}" ]; then
+ rm -f "${resolv_conf_dir}/${interface}"
+ fi
+ if [ ! -d "${resolv_conf_dir}" ]; then
+ mkdir -p "${resolv_conf_dir}"
fi
+ printf "${conf}" > "${resolv_conf_dir}/${interface}"
+ build_resolv_conf
}
-restore_resolv_conf()
+remove_resolv_conf()
{
if type resolvconf >/dev/null 2>&1; then
resolvconf -d "${interface}" -f
else
- restore_conf /etc/resolv.conf || return 0
+ if [ -e "${resolv_conf_dir}/${interface}" ]; then
+ rm -f "${resolv_conf_dir}/${interface}"
+ fi
+ build_resolv_conf
fi
}
case "${reason}" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_resolv_conf;;
-EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_resolv_conf;;
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) add_resolv_conf;;
+PREINIT|EXPIRE|FAIL|IPV4LL|RELEASE|STOP) remove_resolv_conf;;
esac
diff --git a/dhcpcd-hooks/29-lookup-hostname b/dhcpcd-hooks/29-lookup-hostname
index b9ce458..3dfade3 100644
--- a/dhcpcd-hooks/29-lookup-hostname
+++ b/dhcpcd-hooks/29-lookup-hostname
@@ -2,6 +2,7 @@
lookup_hostname()
{
+ [ -z "${new_ip_address}" ] && return 1
local h=
# Silly ISC programs love to send error text to stdout
if type dig >/dev/null 2>&1; then
@@ -23,7 +24,7 @@ lookup_hostname()
set_hostname()
{
- if [ -z "${new_host_name}" ]; then
+ if [ -z "${new_host_name}" -a -z "${new_fqdn_name}" ]; then
export new_host_name="$(lookup_hostname)"
fi
}
diff --git a/dhcpcd-hooks/30-hostname b/dhcpcd-hooks/30-hostname
index 500ec0f..b2e5fc8 100644
--- a/dhcpcd-hooks/30-hostname
+++ b/dhcpcd-hooks/30-hostname
@@ -3,16 +3,23 @@
need_hostname()
{
case "$(hostname)" in
- ""|"(none)"|localhost) [ -n "${new_host_name}" ];;
- "${old_host_name}") true;;
- *) false;;
+ ""|"(none)"|localhost|localhost.localdomain)
+ [ -n "${new_host_name}" -o -n "${new_fqdn_name}" ];;
+ "${old_host_name}"|"${old_fqdn_name}")
+ true;;
+ *)
+ false;;
esac
}
set_hostname()
{
if need_hostname; then
- hostname "${new_host_name}"
+ if [ -n "${new_host_name}" ]; then
+ hostname "${new_host_name}"
+ else
+ hostname "${new_fqdn_name}"
+ fi
fi
}
diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf
index 3772215..536f14e 100644
--- a/dhcpcd-hooks/50-ntp.conf
+++ b/dhcpcd-hooks/50-ntp.conf
@@ -1,4 +1,6 @@
# Sample dhcpcd hook script for ntp
+# Like our resolv.conf hook script, we store a database of ntp.conf files
+# and merge into /etc/ntp.conf
# Detect OpenRC or BSD rc
# Distributions may want to just have their command here instead of this
@@ -10,42 +12,71 @@ elif [ -x /usr/local/etc/rc.d/ntpd ]; then
ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd restart"
fi
-make_ntp_conf()
+ntp_conf_dir="${state_dir}/ntp.conf"
+
+build_ntp_conf()
{
- [ -z "${new_ntp_servers}" ] && return 0
- local cf=/etc/ntp.conf."${interface}" x=
- echo "${signature}" > "${cf}"
- echo "restrict default noquery notrust nomodify" >> "${cf}"
- echo "restrict 127.0.0.1" >> "${cf}"
- for x in ${new_ntp_servers}; do
- echo "restrict ${x} nomodify notrap noquery" >> "${cf}"
- echo "server ${x}" >> "${cf}"
- done
- if [ ! -e /etc/ntp.conf ]; then
- false
- elif type cmp >/dev/null 2>&1; then
- cmp -s /etc/ntp.conf "${cf}"
- elif type diff >/dev/null 2>&1; then
- diff -q /etc/ntp.conf "${cf}" >/dev/null
- else
- false
+ local cf="/etc/ntp.conf.${interface}"
+ local interfaces= header= srvs= servers= x=
+
+ # Build a list of interfaces
+ interfaces=$(list_interfaces "${ntp_conf_dir}")
+
+ if [ -n "${interfaces}" ]; then
+ # Build the header
+ for x in ${interfaces}; do
+ header="${header}${header:+, }${x}"
+ done
+
+ # Build a server list
+ srvs=$(cd "${ntp_conf_dir}";
+ key_get_value "server " ${interfaces})
+ if [ -n "${srvs}" ]; then
+ for x in $(uniqify ${srvs}); do
+ servers="${servers}server ${x}\n"
+ done
+ fi
fi
- if [ $? = 0 ]; then
- rm -f "${cf}"
- else
- save_conf /etc/ntp.conf
- mv -f "${cf}" /etc/ntp.conf
+
+ # Merge our config into ntp.conf
+ [ -e "${cf}" ] && rm -f "${cf}"
+ remove_markers "${signature_base}" "${signature_base_end}" \
+ /etc/ntp.conf > "${cf}"
+ if [ -n "${servers}" ]; then
+ echo "${signature_base}${header:+ ${from} }${header}" >> "${cf}"
+ printf "${search}${servers}" >> "${cf}"
+ echo "${signature_base_end}${header:+ ${from} }${header}" >> "${cf}"
+ fi
+
+ # If we changed anything, restart ntpd
+ if change_file /etc/ntp.conf "${cf}"; then
[ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
fi
}
-restore_ntp_conf()
+add_ntp_conf()
{
- restore_conf /etc/ntp.conf || return 0
- [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
+ local cf="${ntp_conf_dir}/${interface}" x=
+
+ [ -e "${cf}" ] && rm "${cf}"
+ [ -d "${ntp_conf_dir}" ] || mkdir -p "${ntp_conf_dir}"
+ if [ -n "${new_ntp_servers}" ]; then
+ for x in ${new_ntp_servers}; do
+ echo "server ${x}" >> "${cf}"
+ done
+ fi
+ build_ntp_conf
+}
+
+remove_ntp_conf()
+{
+ if [ -e "${ntp_conf_dir}/${interface}" ]; then
+ rm "${ntp_conf_dir}/${interface}"
+ fi
+ build_ntp_conf
}
case "${reason}" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_ntp_conf;;
-EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_ntp_conf;;
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) add_ntp_conf add;;
+PREINIT|EXPIRE|FAIL|IPV4LL|RELEASE|STOP) remove_ntp_conf del;;
esac
diff --git a/dhcpcd-hooks/50-yp.conf b/dhcpcd-hooks/50-yp.conf
index 603f267..a2296eb 100644
--- a/dhcpcd-hooks/50-yp.conf
+++ b/dhcpcd-hooks/50-yp.conf
@@ -10,6 +10,7 @@ make_yp_conf()
{
[ -z "${new_nis_domain}" -a -z "${new_nis_servers}" ] && return 0
local cf=/etc/yp.conf."${interface}" prefix= x= pid=
+ rm -f "${cf}"
echo "${signature}" > "${cf}"
if [ -n "${new_nis_domain}" ]; then
domainname "${new_nis_domain}"
diff --git a/dhcpcd-hooks/90-NetworkManager b/dhcpcd-hooks/90-NetworkManager
index f05ccd7..c4d69fe 100644
--- a/dhcpcd-hooks/90-NetworkManager
+++ b/dhcpcd-hooks/90-NetworkManager
@@ -1,7 +1,8 @@
-# Hook for NetworkManager, relies on D-Bus
+# Hook for NetworkManager-0.7.0
+# NOTE: NetworkManager will override the script dhcpcd calls, so this hook
+# only makes sense if NetworkManager is patched NOT to override the
+# script dhcpcd would call.
-if type dbus-send >/dev/null 2>&1; then
- dbus-send --system --dest=com.redhat.dhcp \
- --type=method_call /com/redhat/dhcp/"${interface}" \
- com.redhat.dhcp.set 'string:'"`env`"
+if [ -x /usr/libexec/nm-dhcp-client.action ]; then
+ /usr/libexec/nm-dhcp-client.action
fi
diff --git a/dhcpcd-hooks/95-configured b/dhcpcd-hooks/95-configured
index 1ff07cf..93f1c43 100644
--- a/dhcpcd-hooks/95-configured
+++ b/dhcpcd-hooks/95-configured
@@ -16,7 +16,11 @@ BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
setprop dhcp.${interface}.result "ok"
;;
-EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
+EXPIRE|FAIL|IPV4LL|STOP)
setprop dhcp.${interface}.result "failed"
;;
+
+RELEASE)
+ setprop dhcp.${interface}.result "released"
+ ;;
esac
diff --git a/dhcpcd-hooks/Makefile b/dhcpcd-hooks/Makefile
index 06660ac..cfb19f7 100644
--- a/dhcpcd-hooks/Makefile
+++ b/dhcpcd-hooks/Makefile
@@ -1,9 +1,11 @@
-LIBEXECDIR= ${PREFIX}/libexec
+LIBEXECDIR?= ${PREFIX}/libexec
HOOKDIR= ${LIBEXECDIR}/dhcpcd-hooks
SYSTEMSCRIPTS= 01-test 10-mtu 20-resolv.conf 30-hostname
FILES= ${SYSTEMSCRIPTS} ${HOOKSCRIPTS}
FILESDIR= ${HOOKDIR}
+all:
+
MK= ../mk
include ${MK}/os.mk
include ${MK}/sys.mk