aboutsummaryrefslogtreecommitdiffstats
path: root/dhcpcd-hooks
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commite95877ecfa1170d77b1ec1f66752725cdda01b64 (patch)
tree81940f62fdf7891f127a1d1ffa712ac1ea1c4c5c /dhcpcd-hooks
downloadexternal_dhcpcd-e95877ecfa1170d77b1ec1f66752725cdda01b64.zip
external_dhcpcd-e95877ecfa1170d77b1ec1f66752725cdda01b64.tar.gz
external_dhcpcd-e95877ecfa1170d77b1ec1f66752725cdda01b64.tar.bz2
Initial Contribution
Diffstat (limited to 'dhcpcd-hooks')
-rw-r--r--dhcpcd-hooks/01-test7
-rw-r--r--dhcpcd-hooks/10-mtu5
-rw-r--r--dhcpcd-hooks/20-dns.conf32
-rw-r--r--dhcpcd-hooks/20-resolv.conf40
-rw-r--r--dhcpcd-hooks/29-lookup-hostname33
-rw-r--r--dhcpcd-hooks/30-hostname21
-rw-r--r--dhcpcd-hooks/50-dhcpcd-compat31
-rw-r--r--dhcpcd-hooks/50-ntp.conf51
-rw-r--r--dhcpcd-hooks/50-yp.conf48
-rw-r--r--dhcpcd-hooks/90-NetworkManager7
-rw-r--r--dhcpcd-hooks/95-configured22
-rw-r--r--dhcpcd-hooks/Makefile11
12 files changed, 308 insertions, 0 deletions
diff --git a/dhcpcd-hooks/01-test b/dhcpcd-hooks/01-test
new file mode 100644
index 0000000..d3ca40d
--- /dev/null
+++ b/dhcpcd-hooks/01-test
@@ -0,0 +1,7 @@
+# Just echo our DHCP options we have
+
+case ${reason} in
+TEST) set | grep "^\(interface\|metric\|pid\|reason\|skip_hooks\)=" | sort
+ set | grep "^\(new_\|old_\)" | sort
+ ;;
+esac
diff --git a/dhcpcd-hooks/10-mtu b/dhcpcd-hooks/10-mtu
new file mode 100644
index 0000000..4265b48
--- /dev/null
+++ b/dhcpcd-hooks/10-mtu
@@ -0,0 +1,5 @@
+# Configure the MTU for the interface
+
+if [ -n "${new_interface_mtu}" ]; then
+ ifconfig "${interface}" mtu "${new_interface_mtu}"
+fi
diff --git a/dhcpcd-hooks/20-dns.conf b/dhcpcd-hooks/20-dns.conf
new file mode 100644
index 0000000..a92e91d
--- /dev/null
+++ b/dhcpcd-hooks/20-dns.conf
@@ -0,0 +1,32 @@
+# Set net.<iface>.dnsN properties that contain the
+# DNS server addresses given by the DHCP server.
+
+set_dns_props()
+{
+ case "${new_domain_name_servers}" in
+ "") return 0;;
+ esac
+
+ count=1
+ for i in 1 2 3 4; do
+ setprop dhcp.${interface}.dns${i} ""
+ done
+
+ count=1
+ for dnsaddr in ${new_domain_name_servers}; do
+ setprop dhcp.${interface}.dns${count} ${dnsaddr}
+ count=$(($count + 1))
+ done
+}
+
+unset_dns_props()
+{
+ for i in 1 2 3 4; do
+ setprop dhcp.${interface}.dns${i} ""
+ done
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_dns_props;;
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP) unset_dns_props;;
+esac
diff --git a/dhcpcd-hooks/20-resolv.conf b/dhcpcd-hooks/20-resolv.conf
new file mode 100644
index 0000000..437c116
--- /dev/null
+++ b/dhcpcd-hooks/20-resolv.conf
@@ -0,0 +1,40 @@
+# Generate /etc/resolv.conf
+# Support resolvconf(8) if available
+
+make_resolv_conf()
+{
+ if [ -z "${new_domain_name_servers}" -a \
+ -z "${new_domain_name}" -a \
+ -z "${new_domain_search}" ]; then
+ return 0
+ 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
+ conf="${conf}search ${new_domain_name}\n"
+ fi
+ for x in ${new_domain_name_servers}; do
+ conf="${conf}nameserver ${x}\n"
+ 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
+ fi
+}
+
+restore_resolv_conf()
+{
+ if type resolvconf >/dev/null 2>&1; then
+ resolvconf -d "${interface}" -f
+ else
+ restore_conf /etc/resolv.conf || return 0
+ fi
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_resolv_conf;;
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_resolv_conf;;
+esac
diff --git a/dhcpcd-hooks/29-lookup-hostname b/dhcpcd-hooks/29-lookup-hostname
new file mode 100644
index 0000000..b9ce458
--- /dev/null
+++ b/dhcpcd-hooks/29-lookup-hostname
@@ -0,0 +1,33 @@
+# Lookup the hostname in DNS if not set
+
+lookup_hostname()
+{
+ local h=
+ # Silly ISC programs love to send error text to stdout
+ if type dig >/dev/null 2>&1; then
+ h=`dig +short -x ${new_ip_address}`
+ if [ $? = 0 ]; then
+ echo "${h}" | sed 's/\.$//'
+ return 0
+ fi
+ elif type host >/dev/null 2>&1; then
+ h=`host ${new_ip_address}`
+ if [ $? = 0 ]; then
+ echo "${h}" \
+ | sed 's/.* domain name pointer \(.*\)./\1/'
+ return 0
+ fi
+ fi
+ return 1
+}
+
+set_hostname()
+{
+ if [ -z "${new_host_name}" ]; then
+ export new_host_name="$(lookup_hostname)"
+ fi
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_hostname;;
+esac
diff --git a/dhcpcd-hooks/30-hostname b/dhcpcd-hooks/30-hostname
new file mode 100644
index 0000000..500ec0f
--- /dev/null
+++ b/dhcpcd-hooks/30-hostname
@@ -0,0 +1,21 @@
+# Set the hostname from DHCP data if required
+
+need_hostname()
+{
+ case "$(hostname)" in
+ ""|"(none)"|localhost) [ -n "${new_host_name}" ];;
+ "${old_host_name}") true;;
+ *) false;;
+ esac
+}
+
+set_hostname()
+{
+ if need_hostname; then
+ hostname "${new_host_name}"
+ fi
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_hostname;;
+esac
diff --git a/dhcpcd-hooks/50-dhcpcd-compat b/dhcpcd-hooks/50-dhcpcd-compat
new file mode 100644
index 0000000..cba40a4
--- /dev/null
+++ b/dhcpcd-hooks/50-dhcpcd-compat
@@ -0,0 +1,31 @@
+# Compat enter hook shim for older dhcpcd versions
+
+IPADDR=${new_ip_address}
+INTERFACE=${interface}
+NETMASK=${new_subnet_mask}
+BROADCAST=${new_broadcast_address}
+NETWORK=${new_network_number}
+DHCPSID=${new_dhcp_server_identifier}
+GATEWAYS=${new_routers}
+DNSSERVERS=${new_domain_name_servers}
+DNSDOMAIN=${new_domain_name}
+DNSSEARCH=${new_domain_search}
+NISDOMAIN=${new_nis_domain}
+NISSERVERS=${new_nis_servers}
+NTPSERVERS=${new_ntp_servers}
+
+GATEWAY=
+for x in ${new_routers}; do
+ GATEWAY="${GATEWAY}${GATEWAY:+,}${x}"
+done
+DNS=
+for x in ${new_domain_name_servers}; do
+ DNS="${DNS}${DNS:+,}${x}"
+done
+
+x="down"
+case "${reason}" in
+RENEW) x="up";;
+BOUND|INFORM|REBIND|REBOOT|TEST|TIMEOUT|IPV4LL) x="new";;
+esac
+set -- "" "${x}"
diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf
new file mode 100644
index 0000000..3772215
--- /dev/null
+++ b/dhcpcd-hooks/50-ntp.conf
@@ -0,0 +1,51 @@
+# Sample dhcpcd hook script for ntp
+
+# Detect OpenRC or BSD rc
+# Distributions may want to just have their command here instead of this
+if type rc-service >/dev/null 2>&1 && rc-service --exists ntpd; then
+ ntpd_restart_cmd="rc-service ntpd -- --ifstarted --quiet restart"
+elif [ -x /etc/rc.d/ntpd ]; then
+ ntpd_restart_cmd="/etc/rc.d/ntpd restart"
+elif [ -x /usr/local/etc/rc.d/ntpd ]; then
+ ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd restart"
+fi
+
+make_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
+ fi
+ if [ $? = 0 ]; then
+ rm -f "${cf}"
+ else
+ save_conf /etc/ntp.conf
+ mv -f "${cf}" /etc/ntp.conf
+ [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
+ fi
+}
+
+restore_ntp_conf()
+{
+ restore_conf /etc/ntp.conf || return 0
+ [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_ntp_conf;;
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_ntp_conf;;
+esac
diff --git a/dhcpcd-hooks/50-yp.conf b/dhcpcd-hooks/50-yp.conf
new file mode 100644
index 0000000..603f267
--- /dev/null
+++ b/dhcpcd-hooks/50-yp.conf
@@ -0,0 +1,48 @@
+# Sample dhcpcd hook for ypbind
+# This script is only suitable for the Linux version.
+
+ypbind_pid()
+{
+ [ -s /var/run/ypbind.pid ] && cat /var/run/ypbind.pid
+}
+
+make_yp_conf()
+{
+ [ -z "${new_nis_domain}" -a -z "${new_nis_servers}" ] && return 0
+ local cf=/etc/yp.conf."${interface}" prefix= x= pid=
+ echo "${signature}" > "${cf}"
+ if [ -n "${new_nis_domain}" ]; then
+ domainname "${new_nis_domain}"
+ if [ -n "${new_nis_servers}" ]; then
+ prefix="domain ${new_nis_domain} server "
+ else
+ echo "domain ${new_nis_domain} broadcast" >> "${cf}"
+ fi
+ else
+ prefix="ypserver "
+ fi
+ for x in ${new_nis_servers}; do
+ echo "${prefix}${x}" >> "${cf}"
+ done
+ save_conf /etc/yp.conf
+ mv -f "${cf}" /etc/yp.conf
+ pid="$(ypbind_pid)"
+ if [ -n "${pid}" ]; then
+ kill -HUP "${pid}"
+ fi
+}
+
+restore_yp_conf()
+{
+ [ -n "${old_nis_domain}" ] && domainname ""
+ restore_conf /etc/yp.conf || return 0
+ local pid="$(ypbind_pid)"
+ if [ -n "${pid}" ]; then
+ kill -HUP "${pid}"
+ fi
+}
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_yp_conf;;
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_yp_conf;;
+esac
diff --git a/dhcpcd-hooks/90-NetworkManager b/dhcpcd-hooks/90-NetworkManager
new file mode 100644
index 0000000..f05ccd7
--- /dev/null
+++ b/dhcpcd-hooks/90-NetworkManager
@@ -0,0 +1,7 @@
+# Hook for NetworkManager, relies on D-Bus
+
+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`"
+fi
diff --git a/dhcpcd-hooks/95-configured b/dhcpcd-hooks/95-configured
new file mode 100644
index 0000000..1ff07cf
--- /dev/null
+++ b/dhcpcd-hooks/95-configured
@@ -0,0 +1,22 @@
+# This script runs last, after all network configuration
+# has completed. It sets a property to let the framework
+# know that setting up the interface is complete.
+
+# For debugging:
+setprop dhcp.${interface}.reason "${reason}"
+
+case "${reason}" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
+ setprop dhcp.${interface}.ipaddress "${new_ip_address}"
+ setprop dhcp.${interface}.gateway "${new_routers%% *}"
+ setprop dhcp.${interface}.mask "${new_subnet_mask}"
+ setprop dhcp.${interface}.leasetime "${new_dhcp_lease_time}"
+ setprop dhcp.${interface}.server "${new_dhcp_server_identifier}"
+
+ setprop dhcp.${interface}.result "ok"
+ ;;
+
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
+ setprop dhcp.${interface}.result "failed"
+ ;;
+esac
diff --git a/dhcpcd-hooks/Makefile b/dhcpcd-hooks/Makefile
new file mode 100644
index 0000000..06660ac
--- /dev/null
+++ b/dhcpcd-hooks/Makefile
@@ -0,0 +1,11 @@
+LIBEXECDIR= ${PREFIX}/libexec
+HOOKDIR= ${LIBEXECDIR}/dhcpcd-hooks
+SYSTEMSCRIPTS= 01-test 10-mtu 20-resolv.conf 30-hostname
+FILES= ${SYSTEMSCRIPTS} ${HOOKSCRIPTS}
+FILESDIR= ${HOOKDIR}
+
+MK= ../mk
+include ${MK}/os.mk
+include ${MK}/sys.mk
+include ${MK}/files.mk
+install: _filesinstall