if (static_lease_ip) {
bb_info_msg("Found static lease: %x", static_lease_ip);
- memcpy(&static_lease.chaddr, &packet.chaddr, 16);
- static_lease.yiaddr = static_lease_ip;
+ memcpy(&static_lease.lease_mac16, &packet.chaddr, 16);
+ static_lease.lease_nip = static_lease_ip;
static_lease.expires = 0;
lease = &static_lease;
DEBUG("server_id = %08x", ntohl(server_id_aligned));
if (server_id_aligned == server_config.server
&& requested
- && requested_aligned == lease->yiaddr
+ && requested_aligned == lease->lease_nip
) {
- send_ACK(&packet, lease->yiaddr);
+ send_ACK(&packet, lease->lease_nip);
}
} else if (requested) {
/* INIT-REBOOT State */
- if (lease->yiaddr == requested_aligned)
- send_ACK(&packet, lease->yiaddr);
+ if (lease->lease_nip == requested_aligned)
+ send_ACK(&packet, lease->lease_nip);
else
send_NAK(&packet);
- } else if (lease->yiaddr == packet.ciaddr) {
+ } else if (lease->lease_nip == packet.ciaddr) {
/* RENEWING or REBINDING State */
- send_ACK(&packet, lease->yiaddr);
+ send_ACK(&packet, lease->lease_nip);
} else { /* don't know what to do!!!! */
send_NAK(&packet);
}
if (lease) {
if (lease_expired(lease)) {
/* probably best if we drop this lease */
- memset(lease->chaddr, 0, 16);
- /* make some contention for this address */
- } else
+ memset(lease->lease_mac16, 0, 16);
+ } else {
+ /* make some contention for this address */
send_NAK(&packet);
+ }
} else {
uint32_t r = ntohl(requested_aligned);
if (r < server_config.start_ip
case DHCPDECLINE:
DEBUG("Received DECLINE");
if (lease) {
- memset(lease->chaddr, 0, 16);
+ memset(lease->lease_mac16, 0, 16);
lease->expires = time(NULL) + server_config.decline_time;
}
break;
typedef int32_t signed_leasetime_t;
struct dhcpOfferedAddr {
- uint8_t chaddr[16];
- /* In network order */
- uint32_t yiaddr;
+ uint8_t lease_mac16[16];
+ /* "nip": IP in network order */
+ uint32_t lease_nip;
/* Unix time when lease expires, regardless of value of
* server_config.remaining. Kept in memory in host order.
* When written to file, converted to network order
while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
const char *fmt = ":%02x" + 1;
for (i = 0; i < 6; i++) {
- printf(fmt, lease.chaddr[i]);
+ printf(fmt, lease.lease_mac16[i]);
fmt = ":%02x";
}
- addr.s_addr = lease.yiaddr;
+ addr.s_addr = lease.lease_nip;
/* actually, 15+1 and 19+1, +1 is a space between columns */
/* lease.hostname is char[20] and is always NUL terminated */
printf(" %-16s%-20s", inet_ntoa(addr), lease.hostname);
for (i = 0; i < server_config.max_leases; i++) {
leasetime_t tmp_time;
- if (leases[i].yiaddr == 0)
+ if (leases[i].lease_nip == 0)
continue;
/* Screw with the time in the struct, for easier writing */
IF_UDHCP_DEBUG(i = 0;)
while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
/* ADDME: what if it matches some static lease? */
- uint32_t y = ntohl(lease.yiaddr);
+ uint32_t y = ntohl(lease.lease_nip);
if (y >= server_config.start_ip && y <= server_config.end_ip) {
signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
if (expires <= 0)
continue;
/* NB: add_lease takes "relative time", IOW,
* lease duration, not lease deadline. */
- if (!(add_lease(lease.chaddr, lease.yiaddr, expires, lease.hostname))) {
+ if (!(add_lease(lease.lease_mac16, lease.lease_nip, expires, lease.hostname))) {
bb_error_msg("too many leases while loading %s", file);
break;
}
continue;
for (i = 0; i < server_config.max_leases; i++) {
- if ((j != 16 && memcmp(leases[i].chaddr, chaddr, 16) == 0)
- || (yiaddr && leases[i].yiaddr == yiaddr)
+ if ((j != 16 && memcmp(leases[i].lease_mac16, chaddr, 16) == 0)
+ || (yiaddr && leases[i].lease_nip == yiaddr)
) {
- memset(&(leases[i]), 0, sizeof(leases[i]));
+ memset(&leases[i], 0, sizeof(leases[i]));
}
}
}
hostname++;
}
}
- memcpy(oldest->chaddr, chaddr, 16);
- oldest->yiaddr = yiaddr;
+ memcpy(oldest->lease_mac16, chaddr, 16);
+ oldest->lease_nip = yiaddr;
oldest->expires = time(NULL) + leasetime;
}
unsigned i;
for (i = 0; i < server_config.max_leases; i++)
- if (!memcmp(leases[i].chaddr, chaddr, 16))
+ if (!memcmp(leases[i].lease_mac16, chaddr, 16))
return &(leases[i]);
return NULL;
unsigned i;
for (i = 0; i < server_config.max_leases; i++)
- if (leases[i].yiaddr == yiaddr)
- return &(leases[i]);
+ if (leases[i].lease_nip == yiaddr)
+ return &leases[i];
return NULL;
}
}
if (oldest_lease && lease_expired(oldest_lease)
- && nobody_responds_to_arp(oldest_lease->yiaddr, chaddr)
+ && nobody_responds_to_arp(oldest_lease->lease_nip, chaddr)
) {
- return oldest_lease->yiaddr;
+ return oldest_lease->lease_nip;
}
return 0;
signed_leasetime_t tmp = lease->expires - time(NULL);
if (tmp >= 0)
lease_time_aligned = tmp;
- packet.yiaddr = lease->yiaddr;
+ packet.yiaddr = lease->lease_nip;
}
/* Or the client has requested an IP */
else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL