aboutsummaryrefslogtreecommitdiffstats
path: root/dhcpcd-hooks/20-resolv.conf
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpcd-hooks/20-resolv.conf')
-rw-r--r--dhcpcd-hooks/20-resolv.conf40
1 files changed, 40 insertions, 0 deletions
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