]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix ntp and nis servers.
authorRoy Marples <roy@marples.name>
Thu, 17 Apr 2008 16:29:22 +0000 (16:29 +0000)
committerRoy Marples <roy@marples.name>
Thu, 17 Apr 2008 16:29:22 +0000 (16:29 +0000)
.gitignore
README
dhcp.c
dhcpcd-compat.sh [deleted file]
dhcpcd.c
dhcpcd.sh.in

index 6eb15919aaaadf83f9d6da11323f11edf1ca6b87..df470627b4d9ae0052c26f5e72ac2a5f41eac8f4 100644 (file)
@@ -2,4 +2,5 @@
 version.h
 dhcpcd
 dhcpcd.8
+dhcpcd.sh
 dhcpcd-*.bz2
diff --git a/README b/README
index 4f62044b0c68ffa88edf89e0369d43839013403b..040a85107c71ad3b36b88a45560a4e15263fb976 100644 (file)
--- a/README
+++ b/README
@@ -20,10 +20,10 @@ If you're cross compiling you may need to set the below knobs to avoid
 automatic tests.
 OS=BSD | Linux
 
-You can change the default dir where dhcpcd stores it's .info files with
-INFODIR=/var/db
+You can change the default dir where dhcpcd stores it's .lease files with
+DBDIR=/var/db
 
-If you're building for a NOMMU system where fork() does not work, youu should
+If you're building for a NOMMU system where fork() does not work, you should
 add -DTHERE_IS_NO_FORK to your CFLAGS.
 
 We now default to using -std=c99. For 64-bit linux, this always works, but
@@ -34,9 +34,16 @@ If your linux headers are older, or your distro hasn't patched them you can
 set CSTD=gnu99 to work around this.
 
 If you require compatibility with dhcpcd-3 and older style variables,
-you can install dhcpcd-compat.sh into the directory /etc/dhcpcd-enter-hook.d
+you can install dhcpcd-compat into the directory /etc/dhcpcd/enter-hook.d
 We don't install this by default.
 
+
+Hooks
+-----
+We provide example exit hooks for NTP and ypbind (Linux).
+There are not installed by default as they are platform dependant.
+
+
 ChangeLog
 ---------
 We no longer supply a ChangeLog.
diff --git a/dhcp.c b/dhcp.c
index da917a419f859b142eb430e073b9229eda439108..e1791a0e0fb582b3c642068406e2118b7d6c0b37 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -98,9 +98,9 @@ const struct dhcp_option dhcp_options[] = {
        { 37,   UINT8,          "default_tcp_ttl" },
        { 38,   UINT32,         "tcp_keepalive_interval" },
        { 39,   UINT8,          "tcp_keepalive_garbage" },
-       { 30,   STRING,         "nis_domain" },
-       { 31,   IPV4 | ARRAY,   "nis_servers" },
-       { 32,   IPV4 | ARRAY,   "ntp_servers" },
+       { 40,   STRING,         "nis_domain" },
+       { 41,   IPV4 | ARRAY,   "nis_servers" },
+       { 42,   IPV4 | ARRAY,   "ntp_servers" },
        { 43,   STRING,         "vendor_encapsulated_options" },
        { 44,   IPV4 | ARRAY,   "netbios_name_servers" },
        { 45,   IPV4,           "netbios_dd_server" },
@@ -394,7 +394,6 @@ decode_rfc3442(const uint8_t *data)
        e = p + l;
        while (p < e) {
                cidr = *p++;
-               printf ("cd %d\n", cidr);
                if (cidr > 32) {
                        free_routes(routes);
                        errno = EINVAL;
@@ -761,8 +760,8 @@ make_message(struct dhcp_message **message,
                *p++ = 0;
                for (l = 0; l < sizeof(dhcp_options) / sizeof(dhcp_options[0]); l++) {
                        o = dhcp_options[l].option;
-                       if (!(dhcp_options[l].type & REQUEST) &&
-                           !has_reqmask(options->reqmask, o))
+                       if (!(dhcp_options[l].type & REQUEST || 
+                             has_reqmask(options->reqmask, o)))
                                continue;
                        switch (o) {
                        case DHCP_RENEWALTIME:  /* FALLTHROUGH */
diff --git a/dhcpcd-compat.sh b/dhcpcd-compat.sh
deleted file mode 100644 (file)
index bb05dfd..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-# Compat shim for older dhcpcd versions
-
-IPADDR=${new_ip_address}
-INTERFACE=${interface}
-NETMASK=${new_subnet_mask}
-BROADCAST=${new_broadcast_address}
-NETWORK=${new_network_address}
-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}"
index 12a51b826c9f3e9a2701a9c5751f065396ae594d..09bd9b27f41ffeab0f41fe44c0ecae145a9c08d5 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -273,6 +273,7 @@ main(int argc, char **argv)
                                logger(LOG_ERR, "unknown option `%s'", optarg);
                                goto abort;
                        }
+                       break;
                case 'p':
                        options->options |= DHCPCD_PERSISTENT;
                        break;
index f97a870053bed5d5cc335742c8ed168b15b5ca0b..a2763e9d814f2bb8b4024b1cd40b5aa1e6387166 100644 (file)
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 
-# OK, this is dhcpcd.sh which is very similar to dhclient-script.
-# Some differences :)
-# 1) The dhcpcd binary configures the interface and routes.
-#    This is so that one script (hopefully!) fits all platforms as the
-#    userland tools vary too much, especially on Linux.
-# 2) We also ship with hooks dir support.
-#    This is meant to be used by applications to install into - the
-#    user is meant to use the top hook script.
-# 3) We support all reasons and variables that dhclient-script does, plus
-#    extra reasons TEST, INFORM and IPV4LL.
-
-# FIXME Move the above into a dhcpcd.sh man page :)
-
 do_hooks()
 {
        local x= r=0
@@ -49,65 +36,6 @@ do_hooks()
        return ${r}
 }
 
-# Try and locate a service pidfile
-service_pid()
-{
-       local service="$1" x=
-       for x in "${service}".pid \
-               "${service}"/pid \
-               "${service}"/"${service}".pid;
-       do
-               if [ -s "/var/run/${x}" ]; then
-                       echo "/var/run/${x}"
-                       return 0
-               fi
-       done
-       return 1
-}
-
-# Try and detect how to handle services so we're pretty
-# platform independant
-do_service()
-{
-       local service="$1" action="$2"
-       shift; shift
-
-       # If restarting check if service is running or not if we can
-       if [ "${action}" = "restart" ]; then
-               pidfile=$(service_pid "${service}")
-               [ -s "${pidfile}" ] || return 0
-               kill -0 $(cat "${pidfile}") 2>/dev/null || return 0
-       fi
-
-       if type rc-service >/dev/null 2>/dev/null; then
-               rc-service "${service}" -- --nodeps "${action}" "$@"
-       elif [ -x /sbin/service ]; then
-               service "${service}" "${action}" "$@"
-       elif [ -x /etc/init.d/"${service}" -a -x /sbin/runscript ]; then
-               /etc/init.d/"${service}" --quiet --nodeps "${action}" "$@"
-       elif [ -x /etc/init.d/"${service}" ]; then
-               /etc/init.d/"${service}" "${action}" "$@"
-       elif [ -x /etc/rc.d/"${service}" ]; then
-               /etc/rc.d/"${service}" "${action}" "$@" 
-       elif [ -x /etc/rc.d/rc."${service}" ]; then
-               /etc/rc.d/rc."${service}" "${action}" "$@"
-       else
-               echo "Don't know how to interact with services on this platform" >&2
-               return 1
-       fi
-}
-
-yesno()
-{
-       [ -z "$1" ] && return 2
-
-       case "$1" in
-               [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
-               [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
-       esac
-       return 2
-}
-
 save_conf()
 {
        if [ -e "$1" ]; then
@@ -123,83 +51,6 @@ restore_conf()
        mv -f "$1"-pre."${interface}" "$1"
 }
 
-set_mtu()
-{
-       if [ -n "${new_mtu}" ]; then
-               ifconfig "${interface}" mtu "${new_mtu}"
-       fi
-}
-
-make_nis_conf() {
-       [ -z "${new_nis_domain}" -a -z "${new_nis_servers}" ] && return 0
-       local cf=/etc/yp.conf."${interface}" prefix= x= pidfile=
-       echo "${signature}" > "${cf}"
-       if [ -n "${new_nis_domain}" ]; then
-               domainname "${new_nis_domain}"
-               if [ -n "${new_nis_server}" ]; 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
-       pidfile="$(service_pidfile ypbind)"
-       if [ -s "${pidfile}" ]; then
-               kill -HUP "${pidfile}"
-       fi
-}
-
-restore_nis_conf()
-{
-       [ -n "${old_nis_domain}" ] && domainname ""
-       restore_conf /etc/yp.conf || return 0
-       pidfile="$(service_pidfile ypbind)"
-       if [ -s "${pidfile}" ]; then
-               kill -HUP "${pidfile}"
-       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
-               true
-       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
-               do_service ntp restart
-       fi
-}
-
-restore_ntp_conf()
-{
-       restore_conf /etc/ntp.conf || return 0
-       do_service ntp restart
-}
-
 make_resolv_conf()
 {
        if [ -z "${new_domain_name_servers}" -a \
@@ -221,7 +72,6 @@ make_resolv_conf()
        else
                save_conf /etc/resolv.conf
                printf "${conf}" > /etc/resolv.conf
-               do_service nscd restart
        fi
 }
 
@@ -231,7 +81,6 @@ restore_resolv_conf()
                resolvconf -d "${interface}" -f
        else
                restore_conf /etc/resolv.conf || return 0
-               do_service nscd restart
        fi
 }
 
@@ -257,7 +106,7 @@ lookup_hostname()
 
 set_hostname()
 {
-       if need_hostname || [ -n "${oldhostname}" ]; then
+       if [ -n "${oldhostname}" ] || need_hostname; then
                local name="${new_hostname}"
                [ -z "${name}" ] && name="$(lookup_hostname)"
                [ -n "${name}" ] && hostname "${name}"
@@ -270,45 +119,24 @@ run_test()
        env | grep "^\(new_\|old_\)" | sort
 }
 
-run_reason()
-{
-       local r=0
-       case "${reason}" in
+signature="# Generated by dhcpcd for ${interface}"
+
+# We should do something with exit codes really
+do_hooks enter
+case "${reason}" in
        TEST)
                run_test
-               r=$?
                ;;
        BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
-               set_mtu
-               r=$((${r} + $?))
                make_resolv_conf
-               r=$((${r} + $?))
                set_hostname
-               r=$((${r} + $?))
-               make_nis_conf
-               r=$((${r} + $?))
-               make_ntp_conf
-               r=$((${r} + $?))
                ;;
        EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
                restore_resolv_conf
-               r=$((${r} + $?))
-               restore_nis_conf
-               r=$((${r} + $?))
-               restore_ntp_conf
-               r=$((${r} + $?))
                ;;
        *)
                echo "unsupported reason ${reason}" >&2
-               return 1
+               false
                ;;
-       esac
-       return ${r}
-}
-
-signature="# Generated by dhcpcd for ${interface}"
-
-# We should do something with exit codes really
-do_hooks enter
-run_reason
+esac
 do_hooks exit