]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd should not send hostname by default.
authorRoy Marples <roy@marples.name>
Thu, 29 Jan 2009 11:21:16 +0000 (11:21 +0000)
committerRoy Marples <roy@marples.name>
Thu, 29 Jan 2009 11:21:16 +0000 (11:21 +0000)
However, the default config file we ship enables the sending of the hostname
by default.
This makes things more explicit I think, and also allows the FQDN to be sent
but not the hostname if someone ever needs this.

dhcp.c
dhcpcd.8.in
dhcpcd.conf
dhcpcd.conf.5.in
if-options.c

diff --git a/dhcp.c b/dhcp.c
index 264189bb7f6b09bf38af39fa705d6e797bb0b33b..e53d27c8864fb7a37000a785c4d54d9688600b89 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -892,7 +892,7 @@ make_message(struct dhcp_message **message,
                 * upto the first dot (the short hostname) as otherwise
                 * confuses some DHCP servers when updating DNS.
                 * The FQDN option should be used if a FQDN is required. */
-               if (ifo->hostname[0]) {
+               if (ifo->options & DHCPCD_HOSTNAME && ifo->hostname[0]) {
                        *p++ = DHO_HOSTNAME;
                        hp = strchr(ifo->hostname, '.');
                        if (hp)
@@ -903,7 +903,7 @@ make_message(struct dhcp_message **message,
                        memcpy(p, ifo->hostname, len);
                        p += len;
                }
-               if (ifo->fqdn != FQDN_DISABLE) {
+               if (ifo->fqdn != FQDN_DISABLE && ifo->hostname[0]) {
                        /* IETF DHC-FQDN option (81), RFC4702 */
                        *p++ = DHO_FQDN;
                        lp = p;
index a3a14907527305c8140e4a9d33cba8c28dc256da..635c094912c32b1738bb0a00dd88b88db2fa15f4 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 5, 2009
+.Dd January 28, 2009
 .Dt DHCPCD 8 SMM
 .Sh NAME
 .Nm dhcpcd
@@ -349,9 +349,6 @@ hostname.
 Valid values for
 .Ar fqdn
 are disable, none, ptr and both.
-The current hostname or the hostname specified using the
-.Fl h , -hostname
-option must be a FQDN.
 .Nm
 itself never does any DNS updates.
 .Nm
index cce1795c7e99124d5398fb3e8497c32af55a1bef..78e55fcb73d64c09b53b2ffd9a80036cd4df3fb2 100644 (file)
@@ -1,9 +1,11 @@
 # A sample configuration for dhcpcd.
 # See dhcpcd.conf(5) for details.
 
-# dhcpcd-run-hooks uses these options.
-option domain_name_servers, domain_name, domain_search, host_name
+# We normally want to inform the DHCP server of our hostname for DDNS.
+hostname
 
+# A list of options we should request from the DHCP server.
+option domain_name_servers, domain_name, domain_search, host_name
 # Most distros have ntp support.
 option ntp_servers
 
index 629a948a6757fcd73d03563c8efb2d21393e79d0..e1976e3abc2b3f3c57768b4fa2fc8890560a3882 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 5, 2009
+.Dd January 28, 2009
 .Dt DHCPCD.CONF 5 SMM
 .Sh NAME
 .Nm dhcpcd.conf
@@ -98,9 +98,6 @@ if a FQDN (ie, contains a .) then it will be encoded as such.
 .It Ic fqdn Op none | ptr | both
 none disables FQDN encoding, ptr just asks the DHCP server to update the PTR
 record of the host in DNS whereas both also updates the A record.
-The current hostname or the hostname specified using the
-.Ic hostname
-option must be a FQDN.
 .Nm dhcpcd
 itself never does any DNS updates.
 .Nm dhcpcd
index e0090f2b2244b8f166e3dfd8d6c3a25be1cd7764..decc960409e2c541b8403031e33d6279d88e7ec8 100644 (file)
@@ -312,20 +312,23 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                strlcpy(ifo->script, arg, sizeof(ifo->script));
                break;
        case 'h':
-               if (arg)
+               if (arg) {
                        s = parse_string(ifo->hostname,
                                         HOSTNAME_MAX_LEN, arg);
-               else
-                       s = 0;
-               if (s == -1) {
-                       syslog(LOG_ERR, "hostname: %m");
-                       return -1;
-               }
-               if (s != 0 && ifo->hostname[0] == '.') {
-                       syslog(LOG_ERR, "hostname cannot begin with a .");
-                       return -1;
+                       if (s == -1) {
+                               syslog(LOG_ERR, "hostname: %m");
+                               return -1;
+                       }
+                       if (s != 0 && ifo->hostname[0] == '.') {
+                               syslog(LOG_ERR, "hostname cannot begin with .");
+                               return -1;
+                       }
+                       ifo->hostname[s] = '\0';
                }
-               ifo->hostname[s] = '\0';
+               if (ifo->hostname[0] == '\0')
+                       ifo->options &= ~DHCPCD_HOSTNAME;
+               else
+                       ifo->options |= DHCPCD_HOSTNAME;
                break;
        case 'i':
                if (arg)
@@ -676,16 +679,16 @@ read_config(const char *file, const char *ifname, const char *ssid)
        ifo->timeout = DEFAULT_TIMEOUT;
        ifo->reboot = DEFAULT_REBOOT;
        ifo->metric = -1;
+       strlcpy(ifo->script, SCRIPT, sizeof(ifo->script));
        gethostname(ifo->hostname, HOSTNAME_MAX_LEN);
        /* Ensure that the hostname is NULL terminated */
        ifo->hostname[HOSTNAME_MAX_LEN] = '\0';
        if (strcmp(ifo->hostname, "(none)") == 0 ||
            strcmp(ifo->hostname, "localhost") == 0)
                ifo->hostname[0] = '\0';
-       strlcpy(ifo->script, SCRIPT, sizeof(ifo->script));
        ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,
-                                            VENDORCLASSID_MAX_LEN,
-                                            "%s %s", PACKAGE, VERSION);
+                                        VENDORCLASSID_MAX_LEN,
+                                        "%s %s", PACKAGE, VERSION);
 
        /* Parse our options file */
        f = fopen(file ? file : CONFIG, "r");
@@ -698,8 +701,8 @@ read_config(const char *file, const char *ifname, const char *ssid)
                if (line && *line) {
                        p = line + strlen(line) - 1;
                        while (p != line &&
-                                       (*p == ' ' || *p == '\t') &&
-                                       *(p - 1) != '\\')
+                              (*p == ' ' || *p == '\t') &&
+                              *(p - 1) != '\\')
                                *p-- = '\0';
                }
                /* Start of an interface block, skip if not ours */