Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/dhcpcd/dist Import dhcpcd-6.0.4 with the follow...



details:   https://anonhg.NetBSD.org/src/rev/6196f0e5d156
branches:  trunk
changeset: 788934:6196f0e5d156
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Jul 29 20:35:31 2013 +0000

description:
Import dhcpcd-6.0.4 with the following changes:
* hostname is not stamped on anymore if already set
* hostname will be set to a FQDN when possible as per RFC4702 section 3.1
* a domain is derived from the FQDN if no domain option is set
* add new hostname_short command to send a short hostname for DDNS
* hostname_fqdn is now documented, along with a new server setting and the
  potential problems associated with it
* the FQDN option is no longer sent by default for DHCPv4 messages

diffstat:

 external/bsd/dhcpcd/dist/common.c                    |  12 +++-
 external/bsd/dhcpcd/dist/common.h                    |   4 +-
 external/bsd/dhcpcd/dist/defs.h                      |   4 +-
 external/bsd/dhcpcd/dist/dhcp6.c                     |  36 ++++++++----
 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf |  14 ++++-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname    |  59 +++++++++++++------
 external/bsd/dhcpcd/dist/if-options.c                |   7 ++-
 external/bsd/dhcpcd/dist/if-options.h                |   3 +-
 8 files changed, 99 insertions(+), 40 deletions(-)

diffs (truncated from 369 to 300 lines):

diff -r 72daa52e8b39 -r 6196f0e5d156 external/bsd/dhcpcd/dist/common.c
--- a/external/bsd/dhcpcd/dist/common.c Mon Jul 29 19:18:37 2013 +0000
+++ b/external/bsd/dhcpcd/dist/common.c Mon Jul 29 20:35:31 2013 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: common.c,v 1.1.1.12 2013/06/21 19:33:06 roy Exp $");
+ __RCSID("$NetBSD: common.c,v 1.1.1.13 2013/07/29 20:35:31 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -139,8 +139,9 @@
 }
 
 const char *
-get_hostname(void)
+get_hostname(int short_hostname)
 {
+       char *p;
 
        gethostname(hostname_buffer, sizeof(hostname_buffer));
        hostname_buffer[sizeof(hostname_buffer) - 1] = '\0';
@@ -149,6 +150,13 @@
            strncmp(hostname_buffer, "localhost.", strlen("localhost.")) == 0 ||
            hostname_buffer[0] == '.')
                return NULL;
+
+       if (short_hostname) {
+               p = strchr(hostname_buffer, '.');
+               if (p)
+                       *p = '\0';
+       }
+
        return hostname_buffer;
 }
 
diff -r 72daa52e8b39 -r 6196f0e5d156 external/bsd/dhcpcd/dist/common.h
--- a/external/bsd/dhcpcd/dist/common.h Mon Jul 29 19:18:37 2013 +0000
+++ b/external/bsd/dhcpcd/dist/common.h Mon Jul 29 20:35:31 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.1.1.8 2013/06/21 19:33:08 roy Exp $ */
+/* $NetBSD: common.h,v 1.1.1.9 2013/07/29 20:35:33 roy Exp $ */
 
 /*
  * dhcpcd - DHCP client daemon
@@ -102,7 +102,7 @@
 int set_cloexec(int);
 int set_nonblock(int);
 char *get_line(FILE * __restrict);
-const char *get_hostname(void);
+const char *get_hostname(int);
 extern int clock_monotonic;
 int get_monotonic(struct timeval *);
 ssize_t setvar(char ***, const char *, const char *, const char *);
diff -r 72daa52e8b39 -r 6196f0e5d156 external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Mon Jul 29 19:18:37 2013 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Mon Jul 29 20:35:31 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.1.1.29 2013/07/19 11:52:57 roy Exp $ */
+/* $NetBSD: defs.h,v 1.1.1.30 2013/07/29 20:35:33 roy Exp $ */
 
 /*
  * dhcpcd - DHCP client daemon
@@ -30,7 +30,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "6.0.3"
+#define VERSION                        "6.0.4"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 72daa52e8b39 -r 6196f0e5d156 external/bsd/dhcpcd/dist/dhcp6.c
--- a/external/bsd/dhcpcd/dist/dhcp6.c  Mon Jul 29 19:18:37 2013 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp6.c  Mon Jul 29 20:35:31 2013 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp6.c,v 1.1.1.2 2013/06/22 09:25:33 roy Exp $");
+ __RCSID("$NetBSD: dhcp6.c,v 1.1.1.3 2013/07/29 20:35:33 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -127,9 +127,9 @@
        { D6_OPTION_INFO_REFRESH_TIME,  UINT32,         "info_refresh_time" },
        { D6_OPTION_BCMS_SERVER_D,      RFC3397,        "bcms_server_d" },
        { D6_OPTION_BCMS_SERVER_A,      IPV6A,          "bcms_server_a" },
+       { D6_OPTION_FQDN,               RFC3397,        "fqdn" },
        { D6_OPTION_POSIX_TIMEZONE,     STRING,         "posix_timezone" },
        { D6_OPTION_TZDB_TIMEZONE,      STRING,         "tzdb_timezone" },
-       { D6_OPTION_FQDN,               RFC3397,        "fqdn" },
        { 0, 0, NULL }
 };
 
@@ -383,6 +383,7 @@
        uint32_t u32;
        const struct ipv6_addr *ap;
        const char *hostname = NULL; /* assignment just to appease GCC*/
+       int fqdn;
 
        state = D6_STATE(ifp);
        if (state->send) {
@@ -390,8 +391,23 @@
                state->send = NULL;
        }
 
+       ifo = ifp->options;
+       fqdn = ifo->fqdn;
+
+       if (fqdn == FQDN_DISABLE || ifo->options & DHCPCD_HOSTNAME) {
+               /* We're sending the DHCPv4 hostname option, so send FQDN as
+                * DHCPv6 has no FQDN option and DHCPv4 must not send
+                * hostname and FQDN according to RFC4702 */
+               if (fqdn == FQDN_DISABLE)
+                       fqdn = FQDN_BOTH;
+               if (ifo->hostname[0] == '\0')
+                       hostname = get_hostname(ifo->options &
+                           DHCPCD_HOSTNAME_SHORT ? 1 : 0);
+               else
+                       hostname = ifo->hostname;
+       }
+
        /* Work out option size first */
-       ifo = ifp->options;
        n_options = 0;
        len = 0;
        si = NULL;
@@ -408,13 +424,8 @@
                if (len)
                        len += sizeof(*o);
 
-               if (ifo->fqdn != FQDN_DISABLE) {
-                       if (ifo->hostname[0] == '\0')
-                               hostname = get_hostname();
-                       else
-                               hostname = ifo->hostname;
+               if (fqdn != FQDN_DISABLE)
                        len += sizeof(*o) + 1 + encode_rfc1035(hostname, NULL);
-               }
        }
 
        len += sizeof(*state->send);
@@ -620,11 +631,11 @@
        }
 
        if (state->send->type !=  DHCP6_RELEASE) {
-               if (ifo->fqdn != FQDN_DISABLE) {
+               if (fqdn != FQDN_DISABLE) {
                        o = D6_NEXT_OPTION(o);
                        o->code = htons(D6_OPTION_FQDN);
                        p = D6_OPTION_DATA(o);
-                       switch (ifo->fqdn) {
+                       switch (fqdn) {
                        case FQDN_BOTH:
                                *p = D6_FQDN_BOTH;
                                break;
@@ -2306,7 +2317,8 @@
                                add_option_mask(ifo->requestmask6,
                                    dhc->dhcp6_opt);
                }
-               if (ifo->fqdn != FQDN_DISABLE)
+               if (ifo->fqdn != FQDN_DISABLE ||
+                   ifo->options & DHCPCD_HOSTNAME)
                        add_option_mask(ifo->requestmask6, D6_OPTION_FQDN);
        }
 
diff -r 72daa52e8b39 -r 6196f0e5d156 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf      Mon Jul 29 19:18:37 2013 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf      Mon Jul 29 20:35:31 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: 20-resolv.conf,v 1.1.1.11 2013/06/21 19:33:08 roy Exp $
+# $NetBSD: 20-resolv.conf,v 1.1.1.12 2013/07/29 20:35:33 roy Exp $
 
 # Generate /etc/resolv.conf
 # Support resolvconf(8) if available
@@ -91,6 +91,18 @@
                return $?
        fi
 
+       # Derive a new domain from our various hostname options
+       new_domain_name=
+       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"
diff -r 72daa52e8b39 -r 6196f0e5d156 external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname Mon Jul 29 19:18:37 2013 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname Mon Jul 29 20:35:31 2013 +0000
@@ -1,9 +1,21 @@
-# $NetBSD: 30-hostname,v 1.1.1.9 2013/07/19 11:52:57 roy Exp $
+# $NetBSD: 30-hostname,v 1.1.1.10 2013/07/29 20:35:33 roy Exp $
 
 # Set the hostname from DHCP data if required
 
-# Generally we should not set the system hostname to be fully qualified
-: ${hostname_fqdn:=false}
+# 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()
@@ -43,7 +55,7 @@
 
 need_hostname()
 {
-       local hostname hfqdn
+       local hostname hfqdn=false hshort=false
 
        case "$force_hostname" in
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
@@ -56,14 +68,15 @@
        
        case "$hostname_fqdn" in
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)        hfqdn=true;;
-       *)                                      hfqdn=false;;
+       [Ss][Ee][Rr][Vv][Ee][Rr])               ;;
+       *)                                      hshort=true;;
        esac
 
-       if [ -n "$old_fqdn_name" ]; then
-               if ${hfqdn}; then
-                       [ "$hostname" = "$old_fqdn_name" ]
-               else    
-                       [ "$hostname" = "${old_fqdn_name%%.*}" ]
+       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
@@ -75,9 +88,14 @@
                        else
                                [ "$hostname" = "$old_host_name" ]
                        fi
-               else
+               elif ${hshort}; then
                        [ "$hostname" = "${old_host_name%%.*}" ]
+               else
+                       [ "$hostname" = "$old_host_name" ]
                fi
+       else
+               # No old hostname
+               false
        fi
 }
 
@@ -93,20 +111,21 @@
 
 set_hostname()
 {
-       local hfqdn
+       local hfqdn=false hshort=false
 
        need_hostname || return
 
        case "$hostname_fqdn" in
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)        hfqdn=true;;
-       *)                                      hfqdn=false;;
+       "")                                     ;;
+       *)                                      hshort=true;;
        esac
 
-       if [ -n "$new_fqdn_name" ]; then
-               if ${hfqdn}; then
-                       try_hostname "$new_fqdn_name"
+       if [ -n "$new_fqdn" ]; then
+               if ${hfqdn} || ! ${hshort}; then
+                       try_hostname "$new_fqdn"
                else
-                       try_hostname "${new_fqdn_name%%.*}"
+                       try_hostname "${new_fqdn%%.*}"
                fi
        elif [ -n "$new_host_name" ]; then
                if ${hfqdn}; then
@@ -117,8 +136,10 @@
                        else
                                try_hostname "$new_host_name"
                        fi
+               elif ${hshort}; then



Home | Main Index | Thread Index | Old Index