aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/udhcp/dhcpd.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index d248d2b67..c46e1721e 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -70,8 +70,10 @@ static void add_static_lease(struct static_lease **st_lease_pp,
70} 70}
71 71
72/* Find static lease IP by mac */ 72/* Find static lease IP by mac */
73static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac) 73static uint32_t get_static_nip_by_mac(void *mac)
74{ 74{
75 struct static_lease *st_lease = server_config.static_leases;
76
75 while (st_lease) { 77 while (st_lease) {
76 if (memcmp(st_lease->mac, mac, 6) == 0) 78 if (memcmp(st_lease->mac, mac, 6) == 0)
77 return st_lease->nip; 79 return st_lease->nip;
@@ -81,8 +83,10 @@ static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac)
81 return 0; 83 return 0;
82} 84}
83 85
84static int is_nip_reserved(struct static_lease *st_lease, uint32_t nip) 86static int is_nip_reserved_as_static(uint32_t nip)
85{ 87{
88 struct static_lease *st_lease = server_config.static_leases;
89
86 while (st_lease) { 90 while (st_lease) {
87 if (st_lease->nip == nip) 91 if (st_lease->nip == nip)
88 return 1; 92 return 1;
@@ -288,7 +292,7 @@ static uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arppi
288 if (nip == server_config.server_nip) 292 if (nip == server_config.server_nip)
289 goto next_addr; 293 goto next_addr;
290 /* is this a static lease addr? */ 294 /* is this a static lease addr? */
291 if (is_nip_reserved(server_config.static_leases, nip)) 295 if (is_nip_reserved_as_static(nip))
292 goto next_addr; 296 goto next_addr;
293 297
294 lease = find_lease_by_nip(nip); 298 lease = find_lease_by_nip(nip);
@@ -518,13 +522,13 @@ static NOINLINE void read_leases(const char *file)
518 expires = 0; 522 expires = 0;
519 523
520 /* Check if there is a different static lease for this IP or MAC */ 524 /* Check if there is a different static lease for this IP or MAC */
521 static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac); 525 static_nip = get_static_nip_by_mac(lease.lease_mac);
522 if (static_nip) { 526 if (static_nip) {
523 /* NB: we do not add lease even if static_nip == lease.lease_nip. 527 /* NB: we do not add lease even if static_nip == lease.lease_nip.
524 */ 528 */
525 continue; 529 continue;
526 } 530 }
527 if (is_nip_reserved(server_config.static_leases, lease.lease_nip)) 531 if (is_nip_reserved_as_static(lease.lease_nip))
528 continue; 532 continue;
529 533
530 /* NB: add_lease takes "relative time", IOW, 534 /* NB: add_lease takes "relative time", IOW,
@@ -999,7 +1003,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
999 } 1003 }
1000 1004
1001 /* Look for a static/dynamic lease */ 1005 /* Look for a static/dynamic lease */
1002 static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr); 1006 static_lease_nip = get_static_nip_by_mac(&packet.chaddr);
1003 if (static_lease_nip) { 1007 if (static_lease_nip) {
1004 bb_info_msg("found static lease: %x", static_lease_nip); 1008 bb_info_msg("found static lease: %x", static_lease_nip);
1005 memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); 1009 memcpy(&fake_lease.lease_mac, &packet.chaddr, 6);