]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
When generating a duid, don't use NET/ROM interface.
authorRoy Marples <roy@marples.name>
Thu, 30 May 2013 08:42:47 +0000 (08:42 +0000)
committerRoy Marples <roy@marples.name>
Thu, 30 May 2013 08:42:47 +0000 (08:42 +0000)
If we have no others, just create a LL address.

duid.c

diff --git a/duid.c b/duid.c
index b94b3927ddb1f62d19fc167f57af8b5d9b1e8832..f4fb980a284c401cda11a064ec9f1df19d919ce8 100644 (file)
--- a/duid.c
+++ b/duid.c
@@ -29,6 +29,9 @@
 #define DUID_LLT       1
 #define DUID_LL                3
 
+#include <net/if.h>
+#include <net/if_arp.h>
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
 
+#ifndef ARPHRD_NETROM
+#  define ARPHRD_NETROM        0
+#endif
+
 #include "common.h"
 #include "duid.h"
 #include "net.h"
@@ -71,12 +78,13 @@ make_duid(unsigned char *duid, const struct interface *ifp, uint16_t type)
 }
 
 size_t
-get_duid(unsigned char *duid, const struct interface *ifp)
+get_duid(unsigned char *duid, const struct interface *iface)
 {
        FILE *f;
        int x = 0;
        size_t len = 0;
        char *line;
+       const struct interface *ifp;
 
        /* If we already have a DUID then use it as it's never supposed
         * to change once we have one even if the interfaces do */
@@ -93,25 +101,42 @@ get_duid(unsigned char *duid, const struct interface *ifp)
                if (len)
                        return len;
        } else {
-               if (errno != ENOENT) {
+               if (errno != ENOENT)
                        syslog(LOG_ERR, "error reading DUID: %s: %m", DUID);
-                       return make_duid(duid, ifp, DUID_LL);
-               }
        }
 
        /* No file? OK, lets make one based on our interface */
+       if (iface->family == ARPHRD_NETROM) {
+               syslog(LOG_WARNING, "%s: is a NET/ROM psuedo interface",
+                   iface->name);
+               TAILQ_FOREACH(ifp, ifaces, next) {
+                       if (ifp->family != ARPHRD_NETROM)
+                               break;
+               }
+               if (ifp) {
+                       iface = ifp;
+                       syslog(LOG_WARNING,
+                           "picked interface %s to generate a DUID",
+                           iface->name);
+               } else {
+                       syslog(LOG_WARNING,
+                           "no interfaces have a fixed hardware address");
+                       return make_duid(duid, iface, DUID_LL);
+               }
+       }
+
        if (!(f = fopen(DUID, "w"))) {
                syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
-               return make_duid(duid, ifp, DUID_LL);
+               return make_duid(duid, iface, DUID_LL);
        }
-       len = make_duid(duid, ifp, DUID_LLT);
+       len = make_duid(duid, iface, DUID_LLT);
        x = fprintf(f, "%s\n", hwaddr_ntoa(duid, len));
        fclose(f);
        /* Failed to write the duid? scrub it, we cannot use it */
        if (x < 1) {
                syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
                unlink(DUID);
-               return make_duid(duid, ifp, DUID_LL);
+               return make_duid(duid, iface, DUID_LL);
        }
        return len;
 }