summaryrefslogtreecommitdiffstats
path: root/dhcpcd/dhcpcd-hooks
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-01-30 13:29:46 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-01-30 16:23:03 +0100
commitf2ed769880271654297a4be420f26ab94d39666b (patch)
tree4cbfc23184993e8ef11bb1d60b307cbb3644a259 /dhcpcd/dhcpcd-hooks
parentarphole: New test (diff)
downloadrtems-libbsd-f2ed769880271654297a4be420f26ab94d39666b.tar.bz2
DHCPCD(8): Import
Import DHCPCD(8) from: http://roy.marples.name/projects/dhcpcd/ The upstream sources can be obtained via: fossil clone http://roy.marples.name/projects/dhcpcd The imported version is 2014-01-29 19:46:44 [6b209507bb].
Diffstat (limited to 'dhcpcd/dhcpcd-hooks')
-rw-r--r--dhcpcd/dhcpcd-hooks/01-test6
-rw-r--r--dhcpcd/dhcpcd-hooks/02-dump5
-rw-r--r--dhcpcd/dhcpcd-hooks/10-mtu38
-rw-r--r--dhcpcd/dhcpcd-hooks/10-wpa_supplicant113
-rw-r--r--dhcpcd/dhcpcd-hooks/15-timezone51
-rw-r--r--dhcpcd/dhcpcd-hooks/20-resolv.conf165
-rw-r--r--dhcpcd/dhcpcd-hooks/29-lookup-hostname34
-rw-r--r--dhcpcd/dhcpcd-hooks/30-hostname154
-rw-r--r--dhcpcd/dhcpcd-hooks/50-dhcpcd-compat41
-rw-r--r--dhcpcd/dhcpcd-hooks/50-ntp.conf109
-rw-r--r--dhcpcd/dhcpcd-hooks/50-yp.conf56
-rw-r--r--dhcpcd/dhcpcd-hooks/50-ypbind78
-rw-r--r--dhcpcd/dhcpcd-hooks/Makefile35
13 files changed, 885 insertions, 0 deletions
diff --git a/dhcpcd/dhcpcd-hooks/01-test b/dhcpcd/dhcpcd-hooks/01-test
new file mode 100644
index 00000000..ac71f089
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/01-test
@@ -0,0 +1,6 @@
+# Just echo our DHCP options we have
+
+if [ "$reason" = "TEST" ]; then
+ set | grep "^\(interface\|metric\|pid\|reason\|skip_hooks\)=" | sort
+ set | grep "^\(new_\|old_\|ra_count=\|ra[0-9]*_\)" | sort
+fi
diff --git a/dhcpcd/dhcpcd-hooks/02-dump b/dhcpcd/dhcpcd-hooks/02-dump
new file mode 100644
index 00000000..cbb46eae
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/02-dump
@@ -0,0 +1,5 @@
+# Just echo our DHCP options we have
+
+if [ "$reason" = "DUMP" ]; then
+ set | sed -ne 's/^new_//p' | sort
+fi
diff --git a/dhcpcd/dhcpcd-hooks/10-mtu b/dhcpcd/dhcpcd-hooks/10-mtu
new file mode 100644
index 00000000..f8657cbd
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/10-mtu
@@ -0,0 +1,38 @@
+# Configure the MTU for the interface
+
+mtu_dir="$state_dir/mtu"
+
+set_mtu()
+{
+ local mtu=$1
+
+ if [ -w /sys/class/net/$interface/mtu ]; then
+ echo "$mtu" >/sys/class/net/$interface/mtu
+ else
+ ifconfig "$interface" mtu "$mtu"
+ fi
+}
+
+if [ "$reason" = PREINIT -a -e "$mtu_dir/$interface" ]; then
+ rm "$mtu_dir/$interface"
+elif [ -n "$new_interface_mtu" ] && $if_up; then
+ # The smalled MTU dhcpcd can work with is 576
+ if [ "$new_interface_mtu" -ge 576 ]; then
+ if set_mtu "$new_interface_mtu"; then
+ syslog info "MTU set to $new_interface_mtu"
+ # Save the MTU so we can restore it later
+ if [ ! -e "$mtu_dir/$interface" ]; then
+ mkdir -p "$mtu_dir"
+ echo "$ifmtu" > "$mtu_dir/$interface"
+ fi
+ fi
+ fi
+elif [ -e "$mtu_dir/$interface" ]; then
+ if $if_up || $if_down; then
+ # No MTU in this state, so restore the prior MTU
+ mtu=$(cat "$mtu_dir/$interface")
+ syslog info "MTU restored to $mtu"
+ set_mtu "$mtu"
+ rm "$mtu_dir/$interface"
+ fi
+fi
diff --git a/dhcpcd/dhcpcd-hooks/10-wpa_supplicant b/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
new file mode 100644
index 00000000..a0dc018e
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
@@ -0,0 +1,113 @@
+# Start, reconfigure and stop wpa_supplicant per wireless interface.
+# This is needed because wpa_supplicant lacks hotplugging of any kind
+# and the user should not be expected to have to wire it into their system
+# if the base system doesn't do this itself.
+
+if [ -z "$wpa_supplicant_conf" ]; then
+ for x in \
+ /etc/wpa_supplicant/wpa_supplicant-"$interface".conf \
+ /etc/wpa_supplicant/wpa_supplicant.conf \
+ /etc/wpa_supplicant-"$interface".conf \
+ /etc/wpa_supplicant.conf \
+ ; do
+ if [ -s "$x" ]; then
+ wpa_supplicant_conf="$x"
+ break
+ fi
+ done
+fi
+: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}
+
+wpa_supplcant_ctrldir() {
+ local dir
+
+ dir=$(key_get_value "[[:space:]]*ctrl_interface=" \
+ "$wpa_supplicant_conf")
+ dir=$(trim "$dir")
+ case "$dir" in
+ DIR=*)
+ dir=${dir##DIR=}
+ dir=${dir%%[[:space:]]GROUP=*}
+ dir=$(trim "$dir")
+ ;;
+ esac
+ printf %s "$dir"
+}
+
+wpa_supplicant_start()
+{
+ local dir err errn
+
+ # Pre flight checks
+ if [ ! -s "$wpa_supplicant_conf" ]; then
+ syslog warn \
+ "$wpa_supplicant_conf does not exist"
+ syslog warn "not interacting with wpa_supplicant(8)"
+ return 1
+ fi
+ dir=$(wpa_supplcant_ctrldir)
+ if [ -z "$dir" ]; then
+ syslog warn \
+ "ctrl_interface not defined in $wpa_supplicant_conf"
+ syslog warn "not interacting with wpa_supplicant(8)"
+ return 1
+ fi
+
+ wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 && return 0
+ syslog info "starting wpa_supplicant"
+ err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" 2>&1)
+ errn=$?
+ if [ $errn != 0 ]; then
+ syslog err "failed to start wpa_supplicant"
+ syslog err "$err"
+ fi
+ return $errn
+}
+
+wpa_supplicant_reconfigure()
+{
+ local dir err errn
+
+ dir=$(wpa_supplcant_ctrldir)
+ [ -z "$dir" ] && return 1
+ if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then
+ wpa_supplicant_start
+ return $?
+ fi
+ syslog info "reconfiguring wpa_supplicant"
+ err=$(wpa_cli -p "$dir" -i "$interface" reconfigure 2>&1)
+ errn=$?
+ if [ $errn != 0 ]; then
+ syslog err "failed to reconfigure wpa_supplicant"
+ syslog err "$err"
+ fi
+ return $errn
+}
+
+wpa_supplicant_stop()
+{
+ local dir err errn
+
+ dir=$(wpa_supplcant_ctrldir)
+ [ -z "$dir" ] && return 1
+ wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0
+ syslog info "stopping wpa_supplicant"
+ err=$(wpa_cli -i"$interface" terminate 2>&1)
+ errn=$?
+ if [ $errn != 0 ]; then
+ syslog err "failed to start wpa_supplicant"
+ syslog err "$err"
+ fi
+ return $errn
+}
+
+if [ "$ifwireless" = "1" ] && \
+ type wpa_supplicant >/dev/null 2>&1 && \
+ type wpa_cli >/dev/null 2>&1
+then
+ case "$reason" in
+ PREINIT) wpa_supplicant_start;;
+ RECONFIGURE) wpa_supplicant_reconfigure;;
+ DEPARTED) wpa_supplicant_stop;;
+ esac
+fi
diff --git a/dhcpcd/dhcpcd-hooks/15-timezone b/dhcpcd/dhcpcd-hooks/15-timezone
new file mode 100644
index 00000000..23ae924c
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/15-timezone
@@ -0,0 +1,51 @@
+# Configure timezone
+
+: ${localtime:=/etc/localtime}
+
+set_zoneinfo()
+{
+ local zoneinfo_dir= zone_file=
+
+ [ -z "$new_tzdb_timezone" ] && return 0
+
+ for d in \
+ /usr/share/zoneinfo \
+ /usr/lib/zoneinfo \
+ /var/share/zoneinfo \
+ /var/zoneinfo \
+ ; do
+ if [ -d "$d" ]; then
+ zoneinfo_dir="$d"
+ break
+ fi
+ done
+
+ if [ -z "$zoneinfo_dir" ]; then
+ syslog warning "timezone directory not found"
+ return 1
+ fi
+
+ zone_file="$zoneinfo_dir/$new_tzdb_timezone"
+ if [ ! -e "$zone_file" ]; then
+ syslog warning "no timezone definition for $new_tzdb_timezone"
+ return 1
+ fi
+
+ syslog info "timezone changed to $new_tzdb_timezone"
+ if [ -h "$localtime" ]; then
+ ln -sf "$zone_file" "$localtime"
+ else
+ cp "$zone_file" "$localtime"
+ fi
+}
+
+# For ease of use, map DHCP6 names onto our DHCP4 names
+case "$reason" in
+BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
+ new_tzdb_timezone="$new_dhcp6_tzdb_timezone"
+ ;;
+esac
+
+if $if_up; then
+ set_zoneinfo
+fi
diff --git a/dhcpcd/dhcpcd-hooks/20-resolv.conf b/dhcpcd/dhcpcd-hooks/20-resolv.conf
new file mode 100644
index 00000000..05316c9f
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/20-resolv.conf
@@ -0,0 +1,165 @@
+# 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.
+
+resolv_conf_dir="$state_dir/resolv.conf"
+NL="
+"
+
+build_resolv_conf()
+{
+ local cf="$state_dir/resolv.conf.$ifname"
+ 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
+ domain=$(cd "$resolv_conf_dir"; \
+ key_get_value "domain " ${interfaces})
+ search=$(cd "$resolv_conf_dir"; \
+ key_get_value "search " ${interfaces})
+ set -- ${domain}
+ domain="$1"
+ [ -n "$2" ] && search="$search $*"
+ [ -n "$search" ] && search="$(uniqify $search)"
+ [ "$domain" = "$search" ] && search=
+ [ -n "$domain" ] && domain="domain $domain$NL"
+ [ -n "$search" ] && search="search $search$NL"
+
+ # Build the nameserver list
+ srvs=$(cd "$resolv_conf_dir"; \
+ key_get_value "nameserver " ${interfaces})
+ for x in $(uniqify ${srvs}); do
+ servers="${servers}nameserver $x$NL"
+ done
+ fi
+ header="$signature_base${header:+ $from }$header"
+
+ # Assemble resolv.conf using our head and tail files
+ [ -f "$cf" ] && rm -f "$cf"
+ [ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
+ 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 %s "$domain$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
+ if change_file /etc/resolv.conf "$cf"; then
+ chmod 644 /etc/resolv.conf
+ fi
+ rm -f "$cf"
+}
+
+add_resolv_conf()
+{
+ local x= conf="$signature$NL" i=${ra_count:-0} ra=
+
+ while [ $i -ne 0 ]; do
+ eval ra=\$ra${i}_rdnss
+ new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$ra"
+ eval ra=\$ra${i}_dnssl
+ new_domain_search="$new_domain_search${new_domain_search:+ }$ra"
+ i=$(($i - 1))
+ done
+
+ # 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
+ remove_resolv_conf
+ return $?
+ fi
+
+ # Derive a new domain from our various hostname options
+ if [ -z "$new_domain_name" ]; then
+ if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
+ new_domain_name="${new_dhcp6_fqdn#*.}"
+ elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
+ new_domain_name="${new_fqdn#*.}"
+ elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
+ new_domain_name="${new_host_name#*.}"
+ fi
+ fi
+
+ if [ -n "$new_domain_name" ]; then
+ set -- $new_domain_name
+ new_domain_name="$1"
+ if valid_domainname "$new_domain_name"; then
+ conf="${conf}domain $new_domain_name$NL"
+ else
+ syslog err "Invalid domain name: $new_domain_name"
+ fi
+ # Support RFC violating search in domain
+ if [ -z "$new_domain_search" -a -n "$2" ]; then
+ new_domain_search="$*"
+ fi
+ fi
+ if [ -n "$new_domain_search" -a \
+ "$new_domain_search" != "$new_domain_name" ]
+ then
+ if valid_domainname_list $new_domain_search; then
+ conf="${conf}search $new_domain_search$NL"
+ else
+ syslog err "Invalid domain name in list: $new_domain_search"
+ fi
+ fi
+ for x in ${new_domain_name_servers}; do
+ conf="${conf}nameserver $x$NL"
+ done
+ if type resolvconf >/dev/null 2>&1; then
+ [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
+ printf %s "$conf" | resolvconf -a "$ifname"
+ return $?
+ fi
+
+ if [ -e "$resolv_conf_dir/$ifname" ]; then
+ rm -f "$resolv_conf_dir/$ifname"
+ fi
+ [ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
+ printf %s "$conf" > "$resolv_conf_dir/$ifname"
+ build_resolv_conf
+}
+
+remove_resolv_conf()
+{
+ if type resolvconf >/dev/null 2>&1; then
+ resolvconf -d "$ifname" -f
+ else
+ if [ -e "$resolv_conf_dir/$ifname" ]; then
+ rm -f "$resolv_conf_dir/$ifname"
+ fi
+ build_resolv_conf
+ fi
+}
+
+# For ease of use, map DHCP6 names onto our DHCP4 names
+case "$reason" in
+BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
+ new_domain_name_servers="$new_dhcp6_name_servers"
+ new_domain_search="$new_dhcp6_domain_search"
+ ;;
+esac
+
+if $if_up || [ "$reason" = ROUTERADVERT ]; then
+ add_resolv_conf
+elif $if_down; then
+ remove_resolv_conf
+fi
diff --git a/dhcpcd/dhcpcd-hooks/29-lookup-hostname b/dhcpcd/dhcpcd-hooks/29-lookup-hostname
new file mode 100644
index 00000000..8661fccd
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/29-lookup-hostname
@@ -0,0 +1,34 @@
+# Lookup the hostname in DNS if not set
+
+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
+ 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" -a -z "$new_fqdn_name" ]; then
+ export new_host_name="$(lookup_hostname)"
+ fi
+}
+
+if $if_up; then
+ set_hostname
+fi
diff --git a/dhcpcd/dhcpcd-hooks/30-hostname b/dhcpcd/dhcpcd-hooks/30-hostname
new file mode 100644
index 00000000..616fb82a
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/30-hostname
@@ -0,0 +1,154 @@
+# Set the hostname from DHCP data if required
+
+# A hostname can either be a short hostname or a FQDN.
+# hostname_fqdn=true
+# hostname_fqdn=false
+# hostname_fqdn=server
+
+# A value of server means just what the server says, don't manipulate it.
+# This could lead to an inconsistent hostname on a DHCPv4 and DHCPv6 network
+# where the DHCPv4 hostname is short and the DHCPv6 has an FQDN.
+# DHCPv6 has no hostname option.
+# RFC4702 section 3.1 says FQDN should be prefered over hostname.
+#
+# As such, the default is hostname_fqdn=true so that a consistent hostname
+# is always assigned.
+: ${hostname_fqdn:=true}
+
+# Some systems don't have hostname(1)
+_hostname()
+{
+ local name=
+
+ if [ -z "$1" ]; then
+ if type hostname >/dev/null 2>&1; then
+ hostname
+ elif [ -r /proc/sys/kernel/hostname ]; then
+ read name </proc/sys/kernel/hostname && echo "$name"
+ elif sysctl kern.hostname >/dev/null 2>&1; then
+ sysctl -n kern.hostname
+ elif sysctl kernel.hostname >/dev/null 2>&1; then
+ sysctl -n kernel.hostname
+ else
+ return 1
+ fi
+ return $?
+ fi
+
+ # Always prefer hostname(1) if we have it
+ if type hostname >/dev/null 2>&1; then
+ hostname "$1"
+ elif [ -w /proc/sys/kernel/hostname ]; then
+ echo "$1" >/proc/sys/kernel/hostname
+ elif sysctl kern.hostname >/dev/null 2>&1; then
+ sysctl -w "kern.hostname=$1"
+ elif sysctl kernel.hostname >/dev/null 2>&1; then
+ sysctl -w "kernel.hostname=$1"
+ else
+ # We know this will fail, but it will now fail
+ # with an error to stdout
+ hostname "$1"
+ fi
+}
+
+need_hostname()
+{
+ local hostname hfqdn=false hshort=false
+
+ case "$force_hostname" in
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
+ esac
+
+ hostname="$(_hostname)"
+ case "$hostname" in
+ ""|"(none)"|localhost|localhost.localdomain) return 0;;
+ esac
+
+ case "$hostname_fqdn" in
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
+ [Ss][Ee][Rr][Vv][Ee][Rr]) ;;
+ *) hshort=true;;
+ esac
+
+ if [ -n "$old_fqdn" ]; then
+ if ${hfqdn} || ! ${hsort}; then
+ [ "$hostname" = "$old_fqdn" ]
+ else
+ [ "$hostname" = "${old_fqdn%%.*}" ]
+ fi
+ elif [ -n "$old_host_name" ]; then
+ if ${hfqdn}; then
+ if [ -n "$old_domain_name" -a \
+ "$old_host_name" = "${old_host_name#*.}" ]
+ then
+ [ "$hostname" = \
+ "$old_host_name.$old_domain_name" ]
+ else
+ [ "$hostname" = "$old_host_name" ]
+ fi
+ elif ${hshort}; then
+ [ "$hostname" = "${old_host_name%%.*}" ]
+ else
+ [ "$hostname" = "$old_host_name" ]
+ fi
+ else
+ # No old hostname
+ false
+ fi
+}
+
+try_hostname()
+{
+
+ if valid_domainname "$1"; then
+ _hostname "$1"
+ else
+ syslog err "Invalid hostname: $1"
+ fi
+}
+
+set_hostname()
+{
+ local hfqdn=false hshort=false
+
+ need_hostname || return
+
+ case "$hostname_fqdn" in
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
+ "") ;;
+ *) hshort=true;;
+ esac
+
+ if [ -n "$new_fqdn" ]; then
+ if ${hfqdn} || ! ${hshort}; then
+ try_hostname "$new_fqdn"
+ else
+ try_hostname "${new_fqdn%%.*}"
+ fi
+ elif [ -n "$new_host_name" ]; then
+ if ${hfqdn}; then
+ if [ -n "$new_domain_name" -a \
+ "$new_host_name" = "${new_host_name#*.}" ]
+ then
+ try_hostname "$new_host_name.$new_domain_name"
+ else
+ try_hostname "$new_host_name"
+ fi
+ elif ${hshort}; then
+ try_hostname "${new_host_name%%.*}"
+ else
+ try_hostname "$new_host_name"
+ fi
+ fi
+}
+
+# For ease of use, map DHCP6 names onto our DHCP4 names
+case "$reason" in
+BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
+ new_fqdn="$new_dhcp6_fqdn"
+ ;;
+esac
+
+if $if_up; then
+ set_hostname
+fi
diff --git a/dhcpcd/dhcpcd-hooks/50-dhcpcd-compat b/dhcpcd/dhcpcd-hooks/50-dhcpcd-compat
new file mode 100644
index 00000000..0d6256e6
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/50-dhcpcd-compat
@@ -0,0 +1,41 @@
+# 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
+
+r="down"
+case "$reason" in
+RENEW) r="up";;
+BOUND|INFORM|REBIND|REBOOT|TEST|TIMEOUT|IPV4LL) r="new";;
+esac
+
+if [ "$r" != "down" ]; then
+ rm -f /var/lib/dhcpcd-"$INTERFACE".info
+ for x in IPADDR INTERFACE NETMASK BROADCAST NETWORK DHCPSID GATEWAYS \
+ DNSSERVERS DNSDOMAIN DNSSEARCH NISDOMAIN NISSERVERS \
+ NTPSERVERS GATEWAY DNS; do
+ eval echo "$x=\'\$$x\'" >> /var/lib/dhcpcd-"$INTERFACE".info
+ done
+fi
+
+set -- /var/lib/dhcpcd-"$INTERFACE".info "$r"
diff --git a/dhcpcd/dhcpcd-hooks/50-ntp.conf b/dhcpcd/dhcpcd-hooks/50-ntp.conf
new file mode 100644
index 00000000..c0781360
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/50-ntp.conf
@@ -0,0 +1,109 @@
+# 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
+
+# You can set the env var NTP_CONF to another file like this
+# dhcpcd -e NTP_CONF=/usr/pkg/etc/ntpd.conf
+# or by adding this to /etc/dhcpcd.enter-hook
+# NTP_CONF=/usr/pkg/etc/ntpd.conf
+# to use openntpd from pkgsrc instead of the system provided ntp.
+
+if type invoke-rc.d >/dev/null 2>&1; then
+ # Debian has a seperate file for DHCP config to avoid stamping on
+ # the master.
+ [ -e /var/lib/ntp ] || mkdir /var/lib/ntp
+ : ${ntp_service:=ntp}
+ : ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
+fi
+
+: ${ntp_service:=ntpd}
+: ${ntp_restart_cmd:=service_condcommand $ntp_service restart}
+ntp_conf_dir="$state_dir/ntp.conf"
+ntp_conf=${NTP_CONF:-/etc/ntp.conf}
+NL="
+"
+
+build_ntp_conf()
+{
+ local cf="$state_dir/ntp.conf.$ifname"
+ 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$NL"
+ done
+ fi
+ fi
+
+ # Merge our config into ntp.conf
+ [ -e "$cf" ] && rm -f "$cf"
+ [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
+
+ if [ -n "$NTP_DHCP_CONF" ]; then
+ [ -e "$ntp_conf" ] && cp "$ntp_conf" "$cf"
+ ntp_conf="$NTP_DHCP_CONF"
+ elif [ -e "$ntp_conf" ]; then
+ remove_markers "$signature_base" "$signature_base_end" \
+ "$ntp_conf" > "$cf"
+ fi
+
+ if [ -n "$servers" ]; then
+ echo "$signature_base${header:+ $from }$header" >> "$cf"
+ printf %s "$servers" >> "$cf"
+ echo "$signature_base_end${header:+ $from }$header" >> "$cf"
+ else
+ [ -e "$ntp_conf" -a -e "$cf" ] || return
+ fi
+
+ # If we changed anything, restart ntpd
+ if change_file "$ntp_conf" "$cf"; then
+ [ -n "$ntp_restart_cmd" ] && eval $ntp_restart_cmd
+ fi
+}
+
+add_ntp_conf()
+{
+ local cf="$ntp_conf_dir/$ifname" 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/$ifname" ]; then
+ rm "$ntp_conf_dir/$ifname"
+ fi
+ build_ntp_conf
+}
+
+# For ease of use, map DHCP6 names onto our DHCP4 names
+case "$reason" in
+BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
+ new_ntp_servers="$new_dhcp6_sntp_servers"
+;;
+esac
+
+if $if_up; then
+ add_ntp_conf add
+elif $if_down; then
+ remove_ntp_conf del
+fi
diff --git a/dhcpcd/dhcpcd-hooks/50-yp.conf b/dhcpcd/dhcpcd-hooks/50-yp.conf
new file mode 100644
index 00000000..2da68ebc
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/50-yp.conf
@@ -0,0 +1,56 @@
+# 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."$ifname" prefix= x= pid=
+ rm -f "$cf"
+ echo "$signature" > "$cf"
+ if [ -n "$new_nis_domain" ]; then
+ if ! valid_domainname "$new_nis_domain"; then
+ syslog err "Invalid NIS domain name: $new_nis_domain"
+ rm -f "$cf"
+ return 1
+ fi
+ 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
+ cat "$cf" > /etc/yp.conf
+ rm -f "$cf"
+ 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
+}
+
+if $if_up; then
+ make_yp_conf
+elif $if_down; then
+ restore_yp_conf
+fi
diff --git a/dhcpcd/dhcpcd-hooks/50-ypbind b/dhcpcd/dhcpcd-hooks/50-ypbind
new file mode 100644
index 00000000..25e009d7
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/50-ypbind
@@ -0,0 +1,78 @@
+# Sample dhcpcd hook for ypbind
+# This script is only suitable for the Linux version.
+
+: ${ypbind_restart_cmd:=service_command ypbind restart}
+: ${ypbind_stop_cmd:=service_condcommand ypbind stop}
+ypbind_dir="$state_dir/ypbind"
+
+best_domain()
+{
+ local i=
+
+ for i in $interfaces; do
+ if [ -e "$ypbind_dir/$i" ]; then
+ cat "$ypbind_dir/$i"
+ fi
+ done
+ return 1
+}
+
+make_yp_binding()
+{
+ [ -d "$ypbind_dir" ] || mkdir -p "$ypbind_dir"
+ echo "$new_nis_domain" >"$ypbind_dir/$ifname"
+ local nd="$(best_domain)"
+
+ local cf=/var/yp/binding/"$new_nis_domain".ypservers
+ if [ -n "$new_nis_servers" ]; then
+ local ncf="$cf.$ifname" x=
+ rm -f "$ncf"
+ for x in $new_nis_servers; do
+ echo "$x" >>"$ncf"
+ done
+ change_file "$cf" "$ncf"
+ else
+ # Because this is not an if .. fi then we can use $? below
+ [ -e "$cf" ] && rm "$cf"
+ fi
+
+ if [ $? = 0 -o "$nd" != "$(domainname)" ]; then
+ domainname "$nd"
+ if [ -n "$ypbind_restart_cmd" ]; then
+ eval $ypbind_restart_cmd
+ fi
+ fi
+}
+
+restore_yp_binding()
+{
+ rm -f "$ypbind_dir/$ifname"
+ local nd="$(best_domain)"
+ # We need to stop ypbind if there is no best domain
+ # otherwise it will just stall as we cannot set domainname
+ # to blank :/
+ if [ -z "$nd" ]; then
+ if [ -n "$ypbind_stop_cmd" ]; then
+ eval $ypbind_stop_cmd
+ fi
+ elif [ "$nd" != "$(domainname)" ]; then
+ domainname "$nd"
+ if [ -n "$ypbind_restart_cmd" ]; then
+ eval $ypbind_restart_cmd
+ fi
+ fi
+}
+
+if [ "$reason" = PREINIT ]; then
+ rm -f "$ypbind_dir/$ifname"
+elif $if_up || $if_down; then
+ if [ -n "$new_nis_domain" ]; then
+ if valid_domainname "$new_nis_domain"; then
+ make_yp_binding
+ else
+ syslog err "Invalid NIS domain name: $new_nis_domain"
+ fi
+ elif [ -n "$old_nis_domain" ]; then
+ restore_yp_binding
+ fi
+fi
diff --git a/dhcpcd/dhcpcd-hooks/Makefile b/dhcpcd/dhcpcd-hooks/Makefile
new file mode 100644
index 00000000..5982f1b7
--- /dev/null
+++ b/dhcpcd/dhcpcd-hooks/Makefile
@@ -0,0 +1,35 @@
+TOP?= ../
+include ${TOP}/Makefile.inc
+include ${TOP}/config.mk
+
+SCRIPTSDIR= ${LIBEXECDIR}/dhcpcd-hooks
+SCRIPTS= 01-test 02-dump
+SCRIPTS+= 10-mtu 10-wpa_supplicant 15-timezone 20-resolv.conf
+SCRIPTS+= 29-lookup-hostname 30-hostname
+SCRIPTS+= ${HOOKSCRIPTS}
+
+all:
+
+clean:
+
+proginstall:
+ ${INSTALL} -d ${DESTDIR}${SCRIPTSDIR}
+ ${INSTALL} -m ${NONBINMODE} ${SCRIPTS} ${DESTDIR}${SCRIPTSDIR}
+
+install: proginstall
+
+import:
+ ${INSTALL} -d /tmp/${DISTPREFIX}/dhcpcd-hooks
+ for x in ${SCRIPTS}; do \
+ t="/tmp/${DISTPREFIX}/dhcpcd-hooks/$$x"; \
+ if test "$$(sed -ne 1p $$x)" = "#!/bin/sh"; then \
+ echo "#!/bin/sh" >"$$t"; \
+ printf "${IMPORT_SHID}\n" >>"$$t"; \
+ echo "" >>"$$t"; \
+ sed 1d "$$x" >>"$$t"; \
+ else \
+ printf "${IMPORT_SHID}\n" >"$$t"; \
+ echo "" >>"$$t"; \
+ cat "$$x" >>"$$t"; \
+ fi; \
+ done;