]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Simplfy
authorRoy Marples <roy@marples.name>
Wed, 22 Oct 2014 04:17:25 +0000 (04:17 +0000)
committerRoy Marples <roy@marples.name>
Wed, 22 Oct 2014 04:17:25 +0000 (04:17 +0000)
ipv4ll.c

index bc37e3760dd4a4056a6969b713f28841eb7b64e1..93a09661301cfd7fd69359e861edeb3936d0b7e2 100644 (file)
--- a/ipv4ll.c
+++ b/ipv4ll.c
@@ -78,20 +78,16 @@ ipv4ll_find_lease(const struct interface *ifp)
        const struct dhcp_state *state;
 
        for (;;) {
-               addr = ntohl(LINKLOCAL_ADDR | random() & 0x0000FFFF);
+               /* RFC 3927 Section 2.1 states that the first 256 and
+                * last 256 addresses are reserved for future use.
+                * See ipv4ll_start for why we don't use arc4_random. */
+               addr = ntohl(LINKLOCAL_ADDR | ((random() % 0xFD00) + 0x0100));
 
                state = D_CSTATE(ifp);
                /* No point using a failed address */
                if (addr == state->fail.s_addr)
                        continue;
 
-               /* RFC 3927 Section 2.1 states that the first 256 and
-                * last 256 addresses are reserved for future use */
-               if (!IN_LINKLOCAL(htonl(addr)) ||
-                   (htonl(addr) & 0x0000FF00) == 0x0000 ||
-                   (htonl(addr) & 0x0000FF00) == 0xFF00)
-                       continue;
-
                /* Ensure we don't have the address on another interface */
                TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
                        state = D_CSTATE(ifp2);
@@ -124,7 +120,8 @@ ipv4ll_start(void *arg)
 
        /* RFC 3927 Section 2.1 states that the random number generator
         * SHOULD be seeded with a value derived from persistent information
-        * such as the IEEE 802 MAC address. */
+        * such as the IEEE 802 MAC address so that it usually picks
+        * the same address without persistent storage. */
        if (state->conflicts == 0) {
                unsigned int seed;