Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/networking/udhcp/leases.c

    r2725 r3232  
    138138    struct dyn_lease *oldest_lease = NULL;
    139139
    140     addr = server_config.start_ip; /* addr is in host order here */
    141     for (; addr <= server_config.end_ip; addr++) {
     140#if ENABLE_FEATURE_UDHCPD_BASE_IP_ON_MAC
     141    uint32_t stop;
     142    unsigned i, hash;
     143
     144    /* hash hwaddr: use the SDBM hashing algorithm.  Seems to give good
     145     * dispersal even with similarly-valued "strings".
     146     */
     147    hash = 0;
     148    for (i = 0; i < 6; i++)
     149        hash += safe_mac[i] + (hash << 6) + (hash << 16) - hash;
     150
     151    /* pick a seed based on hwaddr then iterate until we find a free address. */
     152    addr = server_config.start_ip
     153        + (hash % (1 + server_config.end_ip - server_config.start_ip));
     154    stop = addr;
     155#else
     156    addr = server_config.start_ip;
     157#define stop (server_config.end_ip + 1)
     158#endif
     159    do {
    142160        uint32_t nip;
    143161        struct dyn_lease *lease;
     
    145163        /* ie, 192.168.55.0 */
    146164        if ((addr & 0xff) == 0)
    147             continue;
     165            goto next_addr;
    148166        /* ie, 192.168.55.255 */
    149167        if ((addr & 0xff) == 0xff)
    150             continue;
     168            goto next_addr;
    151169        nip = htonl(addr);
     170        /* skip our own address */
     171        if (nip == server_config.server_nip)
     172            goto next_addr;
    152173        /* is this a static lease addr? */
    153174        if (is_nip_reserved(server_config.static_leases, nip))
    154             continue;
     175            goto next_addr;
    155176
    156177        lease = find_lease_by_nip(nip);
     
    163184                oldest_lease = lease;
    164185        }
    165     }
     186
     187 next_addr:
     188        addr++;
     189#if ENABLE_FEATURE_UDHCPD_BASE_IP_ON_MAC
     190        if (addr > server_config.end_ip)
     191            addr = server_config.start_ip;
     192#endif
     193    } while (addr != stop);
    166194
    167195    if (oldest_lease
Note: See TracChangeset for help on using the changeset viewer.