]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
duid: Allow optional argument to specify ll or llt alongside uuid
authorRoy Marples <roy@marples.name>
Wed, 16 Sep 2020 14:55:11 +0000 (15:55 +0100)
committerRoy Marples <roy@marples.name>
Wed, 16 Sep 2020 14:55:11 +0000 (15:55 +0100)
src/dhcpcd.conf.5.in
src/dhcpcd.h
src/duid.c
src/duid.h
src/if-options.c

index 998f99e92bbd518fb9ed60c01a87aed7bfece242..a5e9958141208cb4c0758c23e7c911a919751500 100644 (file)
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd September 2, 2020
+.Dd September 15, 2020
 .Dt DHCPCD.CONF 5
 .Os
 .Sh NAME
@@ -211,12 +211,15 @@ is an empty string then
 sends a default
 .Ar clientid
 of the hardware family and the hardware address.
-.It Ic duid
+.It Ic duid Op ll | lt | uuid
 Use a DHCP Unique Identifier.
 If a system UUID is available, that will be used to create a DUID-UUID,
 otheriwse if persistent storage is available then a DUID-LLT
 (link local address + time) is generated,
 otherwise DUID-LL is generated (link local address).
+The DUID type can be hinted as an optional parameter if the file
+.Pa @DBDIR@/duid
+does not exist.
 This, plus the IAID will be used as the
 .Ic clientid .
 The DUID generated will be held in
index fdff88a175a046559bbd098fbf628ced98a206ac..03449e5846053d3255087762420ad14c2aa75d70 100644 (file)
@@ -135,6 +135,7 @@ struct dhcpcd_ctx {
        char **ifv;     /* listed interfaces */
        int ifcc;       /* configured interfaces */
        char **ifcv;    /* configured interfaces */
+       uint8_t duid_type;
        unsigned char *duid;
        size_t duid_len;
        struct if_head *ifaces;
index 012874782528076adbad8f6928aeff7dfe64d22d..ce9214fa79b5ec919a0dc36b34fd67505ec85f86 100644 (file)
@@ -176,6 +176,9 @@ duid_get(struct dhcpcd_ctx *ctx, const struct interface *ifp)
 
        /* No file? OK, lets make one based the machines UUID */
        if (ifp == NULL) {
+               if (ctx->duid_type != DUID_DEFAULT &&
+                   ctx->duid_type != DUID_UUID)
+                       return 0;
                len = duid_make_uuid(data);
                if (len == 0)
                        free(data);
@@ -199,13 +202,15 @@ duid_get(struct dhcpcd_ctx *ctx, const struct interface *ifp)
                        logwarnx("picked interface %s to generate a DUID",
                            ifp->name);
                } else {
-                       logwarnx("no interfaces have a fixed hardware "
-                           "address");
+                       if (ctx->duid_type != DUID_LL)
+                               logwarnx("no interfaces have a fixed hardware "
+                                   "address");
                        return duid_make(data, ifp, DUID_LL);
                }
        }
 
-       len = duid_make(data, ifp, DUID_LLT);
+       len = duid_make(data, ifp,
+           ctx->duid_type == DUID_LL ? DUID_LL : DUID_LLT);
        hwaddr_ntoa(data, len, line, sizeof(line));
        slen = strlen(line);
        if (slen < sizeof(line) - 2) {
@@ -214,7 +219,8 @@ duid_get(struct dhcpcd_ctx *ctx, const struct interface *ifp)
        }
        if (dhcp_writefile(ctx, DUID, 0640, line, slen) == -1) {
                logerr("%s: cannot write duid", __func__);
-               return duid_make(data, ifp, DUID_LL);
+               if (ctx->duid_type != DUID_LL)
+                       return duid_make(data, ifp, DUID_LL);
        }
        return len;
 }
index a674bef3187ae6675341866fe445d654be9285aa..1d25f2b66a53574c54cc64ae697b6a6131b92448 100644 (file)
@@ -30,6 +30,7 @@
 #define DUID_H
 
 #define DUID_LEN       128 + 2
+#define        DUID_DEFAULT    0
 #define        DUID_LLT        1
 #define        DUID_LL         3
 #define        DUID_UUID       4
index 213d05cc186b8265c54c390ee486a25492ab36dc..0d6b8e3a39d43b5bd2b70e918e0ce0bdc69922f1 100644 (file)
@@ -49,6 +49,7 @@
 #include "dhcp.h"
 #include "dhcp6.h"
 #include "dhcpcd-embedded.h"
+#include "duid.h"
 #include "if.h"
 #include "if-options.h"
 #include "ipv4.h"
@@ -94,7 +95,7 @@ const struct option cf_options[] = {
        {"noarp",           no_argument,       NULL, 'A'},
        {"nobackground",    no_argument,       NULL, 'B'},
        {"nohook",          required_argument, NULL, 'C'},
-       {"duid",            no_argument,       NULL, 'D'},
+       {"duid",            optional_argument, NULL, 'D'},
        {"lastlease",       no_argument,       NULL, 'E'},
        {"fqdn",            optional_argument, NULL, 'F'},
        {"nogateway",       no_argument,       NULL, 'G'},
@@ -985,6 +986,20 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                break;
        case 'D':
                ifo->options |= DHCPCD_CLIENTID | DHCPCD_DUID;
+               if (ifname != NULL) /* duid type only a global option */
+                       break;
+               if (arg == NULL)
+                       ctx->duid_type = DUID_DEFAULT;
+               else if (strcmp(arg, "ll") == 0)
+                       ctx->duid_type = DUID_LL;
+               else if (strcmp(arg, "llt") == 0)
+                       ctx->duid_type = DUID_LLT;
+               else if (strcmp(arg, "uuid") == 0)
+                       ctx->duid_type = DUID_UUID;
+               else {
+                       logwarnx("%s: invalid duid type", arg);
+                       ctx->duid_type = DUID_DEFAULT;
+               }
                break;
        case 'E':
                ifo->options |= DHCPCD_LASTLEASE;