]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Allow -I to have an optional argument, when missing don't use DUID's
authorRoy Marples <roy@marples.name>
Fri, 11 May 2007 10:51:32 +0000 (10:51 +0000)
committerRoy Marples <roy@marples.name>
Fri, 11 May 2007 10:51:32 +0000 (10:51 +0000)
dhcp.c
dhcpcd.8
dhcpcd.c
dhcpcd.h
duid.c
info.c

diff --git a/dhcp.c b/dhcp.c
index a0dade42857613df0a391733cae17b78c8612c22..a4688be5ce98881b2170c33c7c93497d0c75fb75 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -234,12 +234,11 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
        }
 
        *p++ = DHCP_CLIENTID;
-       if (options->clientid[0]) {
-               l = strlen (options->clientid);
-               *p++ = l + 1;
+       if (options->clientid_len > 0) {
+               *p++ = options->clientid_len + 1;
                *p++ = 0; /* string */
-               memcpy (p, options, l);
-               p += l;
+               memcpy (p, options, options->clientid_len);
+               p += options->clientid_len;
 #ifdef ENABLE_DUID
        } else if (iface->duid) {
                *p++ = iface->duid_length + 5;
index 3ed93b4f5c23a61acf1ed0cdfcc4100d450a8dfb..1878198467f4ac0a8183499be07a71f8ecb1b46b 100644 (file)
--- a/dhcpcd.8
+++ b/dhcpcd.8
@@ -18,8 +18,8 @@ dhcpcd
 \%[\-s\ ipaddr]
 \%[\-t\ timeout]
 \%[\-u\ userClass]
-\%[\-F\ none | ptr | both]
-\%[\-I\ clientID]
+\%[\-F\ [ none | ptr | both ] ]
+\%[\-I\ [ clientID ] ]
 \%[interface]
 .in -.5i
 .SH DESCRIPTION
@@ -217,7 +217,8 @@ Specifies the client identifier string. If not specified then
 will attempt to create a client identifier according to \fBRFC 4361\fR
 and store the DUID part in /var/lib/dhcpcd/dhcpcd.duid, otherwise
 .B dhcpcd
-uses the MAC address of the network interface.
+uses the MAC address of the network interface. If \fB-I\fR is not given
+an option then we use the MAC address of the network interface.
 .TP
 .BI \-M
 Prevents
index 3ac3044846fb80f2ebfc5b51d4c33be2d79b4164..4997e4059dcf69671e312db45de612237df7505e 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -127,7 +127,7 @@ int main(int argc, char **argv)
                {"fqdn",        optional_argument,  NULL, 'F'},
         {"nogateway",   no_argument,        NULL, 'G'},
         {"sethostname", no_argument,        NULL, 'H'},
-        {"clientid",    required_argument,  NULL, 'I'},
+        {"clientid",    optional_argument,  NULL, 'I'},
         {"nomtu",       no_argument,        NULL, 'M'},
         {"nontp",       no_argument,        NULL, 'N'},
         {"nodns",       no_argument,        NULL, 'R'},
@@ -156,8 +156,9 @@ int main(int argc, char **argv)
        options.daemonise = true;
        options.timeout = DEFAULT_TIMEOUT;
 
-       while ((ch = getopt_long(argc, argv, "ac:dh:i:kl:m:nps:t:u:EF:GHI:MNRY", longopts,
+       while ((ch = getopt_long(argc, argv, "ac:dh:i:kl:m:nps:t:u:EF::GHI::MNRY", longopts,
                                                         &option_index)) != -1)
+       {
                switch (ch) {
                        case 0:
                                if (longopts[option_index].flag)
@@ -252,16 +253,19 @@ int main(int argc, char **argv)
                                options.dolastlease = true;
                                break;
                        case 'F':
-                               if (strncmp (optarg, "none", strlen (optarg)) == 0)
-                                       options.fqdn = FQDN_NONE;
-                               else if (strncmp (optarg, "ptr", strlen (optarg)) == 0)
-                                       options.fqdn = FQDN_PTR;
-                               else if (strncmp (optarg, "both", strlen (optarg)) == 0)
+                               if (optarg) {
+                                       if (strncmp (optarg, "none", strlen (optarg)) == 0)
+                                               options.fqdn = FQDN_NONE;
+                                       else if (strncmp (optarg, "ptr", strlen (optarg)) == 0)
+                                               options.fqdn = FQDN_PTR;
+                                       else if (strncmp (optarg, "both", strlen (optarg)) == 0)
+                                               options.fqdn = FQDN_BOTH;
+                                       else {
+                                               logger (LOG_ERR, "invalid value `%s' for FQDN", optarg);
+                                               exit (EXIT_FAILURE);
+                                       }
+                               } else
                                        options.fqdn = FQDN_BOTH;
-                               else {
-                                       logger (LOG_ERR, "invalid value `%s' for FQDN", optarg);
-                                       exit (EXIT_FAILURE);
-                               }
                                break;
                        case 'G':
                                options.dogateway = false;
@@ -270,12 +274,16 @@ int main(int argc, char **argv)
                                options.dohostname = true;
                                break;
                        case 'I':
-                               if (strlen (optarg) > CLIENT_ID_MAX_LEN) {
-                                       logger (LOG_ERR, "`%s' is too long for ClientID, max is %d",
-                                                       optarg, CLIENT_ID_MAX_LEN);
-                                       exit (EXIT_FAILURE);
+                               if (optarg && strlen(optarg) > 0) {
+                                       if (strlen (optarg) > CLIENT_ID_MAX_LEN) {
+                                               logger (LOG_ERR, "`%s' is too long for ClientID, max is %d",
+                                                               optarg, CLIENT_ID_MAX_LEN);
+                                               exit (EXIT_FAILURE);
+                                       } else
+                                               strlcpy (options.clientid, optarg, sizeof (options.clientid));
+                                       options.clientid_len = strlen (options.clientid);
                                } else
-                                       strlcpy (options.clientid, optarg, sizeof (options.clientid));
+                                       options.clientid_len = -1;
                                break;
                        case 'M':
                                options.domtu = false;
@@ -296,7 +304,7 @@ int main(int argc, char **argv)
                                usage ();
                                exit (EXIT_FAILURE);
                }
-
+       }
        if (doversion)
                printf (""PACKAGE" "VERSION"\n");
 
index ff1086f2891068e65e9840f646e5916ee43457f0..a5be73b03b9e520cae042abc414960f07d9a7dd8 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -41,7 +41,9 @@ typedef struct options_t {
        char hostname[MAXHOSTNAMELEN];
        int fqdn;
        char classid[CLASS_ID_MAX_LEN];
+       int classid_len;
        char clientid[CLIENT_ID_MAX_LEN];
+       int clientid_len;
        char userclass[USERCLASS_MAX_LEN];
        int userclass_len;
        unsigned leasetime;
diff --git a/duid.c b/duid.c
index 0376d99c2ec65e020af0ba16544500cfe7a61b22..78f02034813e197442603a78a51d8f13d191ed9c 100644 (file)
--- a/duid.c
+++ b/duid.c
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
 
 #include "config.h"
 #include "common.h"
diff --git a/info.c b/info.c
index 8b1eb7a777b5243ddeb4af967b2d5711c2a338ed..e9f0a2f88c7f2e7fa90d25e050e1c2ead1deb50a 100644 (file)
--- a/info.c
+++ b/info.c
@@ -171,14 +171,16 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp,
        fprintf (f, "REBINDTIME='%u'\n", dhcp->rebindtime);
        fprintf (f, "INTERFACE='%s'\n", iface->name);
        fprintf (f, "CLASSID='%s'\n", cleanmetas (options->classid));
-       if (options->clientid[0])
-               fprintf (f, "CLIENTID='%s'\n", cleanmetas (options->clientid));
+       if (options->clientid_len > 0)
+               fprintf (f, "CLIENTID='00:%s'\n", cleanmetas (options->clientid));
 #ifdef ENABLE_DUID
-       else if (iface->duid_length > 0) {
+       else if (iface->duid_length > 0 && options->clientid_len != -1) {
                unsigned char duid[256];
                unsigned char *p = duid;
                uint32_t ul;
 
+               *p++ = 255;
+
                /* IAID is 4 bytes, so if the interface name is 4 bytes then use it */
                if (strlen (iface->name) == 4) {
                        memcpy (p, iface->name, 4);
@@ -196,7 +198,8 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp,
        }
 #endif
        else
-               fprintf (f, "CLIENTID='%s'\n", hwaddr_ntoa (iface->hwaddr, iface->hwlen));
+               fprintf (f, "CLIENTID='%.2X:%s'\n", iface->family,
+                                hwaddr_ntoa (iface->hwaddr, iface->hwlen));
        fprintf (f, "DHCPCHADDR='%s'\n", hwaddr_ntoa (iface->hwaddr, iface->hwlen));
 
 #ifdef ENABLE_INFO_COMPAT