summaryrefslogtreecommitdiff
path: root/networking/udhcp/leases.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/leases.c')
-rw-r--r--networking/udhcp/leases.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index ceec07345..997daea6c 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -95,24 +95,26 @@ struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr)
95 95
96 96
97/* check is an IP is taken, if it is, add it to the lease table */ 97/* check is an IP is taken, if it is, add it to the lease table */
98static int check_ip(uint32_t addr) 98static int nobody_responds_to_arp(uint32_t addr)
99{ 99{
100 static const uint8_t blank_chaddr[16]; /* 16 zero bytes */ 100 static const uint8_t blank_chaddr[16]; /* 16 zero bytes */
101 101
102 struct in_addr temp; 102 struct in_addr temp;
103 int r;
103 104
104 if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) { 105 r = arpping(addr, server_config.server, server_config.arp, server_config.interface);
105 temp.s_addr = addr; 106 if (r)
106 bb_info_msg("%s belongs to someone, reserving it for %ld seconds", 107 return r;
107 inet_ntoa(temp), server_config.conflict_time); 108
108 add_lease(blank_chaddr, addr, server_config.conflict_time); 109 temp.s_addr = addr;
109 return 1; 110 bb_info_msg("%s belongs to someone, reserving it for %u seconds",
110 } 111 inet_ntoa(temp), (unsigned)server_config.conflict_time);
112 add_lease(blank_chaddr, addr, server_config.conflict_time);
111 return 0; 113 return 0;
112} 114}
113 115
114 116
115/* find an assignable address, it check_expired is true, we check all the expired leases as well. 117/* find an assignable address, if check_expired is true, we check all the expired leases as well.
116 * Maybe this should try expired leases by age... */ 118 * Maybe this should try expired leases by age... */
117uint32_t find_address(int check_expired) 119uint32_t find_address(int check_expired)
118{ 120{
@@ -129,15 +131,14 @@ uint32_t find_address(int check_expired)
129 if ((addr & 0xFF) == 0xFF) continue; 131 if ((addr & 0xFF) == 0xFF) continue;
130 132
131 /* Only do if it isn't assigned as a static lease */ 133 /* Only do if it isn't assigned as a static lease */
132 if (!reservedIp(server_config.static_leases, htonl(addr))) { 134 ret = htonl(addr);
133 135 if (!reservedIp(server_config.static_leases, ret)) {
134 /* lease is not taken */ 136 /* lease is not taken */
135 ret = htonl(addr);
136 lease = find_lease_by_yiaddr(ret); 137 lease = find_lease_by_yiaddr(ret);
137 138
138 /* no lease or it expired and we are checking for expired leases */ 139 /* no lease or it expired and we are checking for expired leases */
139 if ((!lease || (check_expired && lease_expired(lease))) 140 if ((!lease || (check_expired && lease_expired(lease)))
140 && /* and it isn't on the network */ !check_ip(ret) 141 && nobody_responds_to_arp(ret) /* it isn't used on the network */
141 ) { 142 ) {
142 return ret; 143 return ret;
143 } 144 }