2006-07-02 19:47:05 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2006-05-08 03:20:50 +00:00
|
|
|
/*
|
2010-03-26 09:09:34 +00:00
|
|
|
* Storing and retrieving data for static leases
|
2006-05-08 03:20:50 +00:00
|
|
|
*
|
|
|
|
* Wade Berrier <wberrier@myrealbox.com> September 2004
|
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
2006-05-08 03:20:50 +00:00
|
|
|
*/
|
2006-11-18 19:51:32 +00:00
|
|
|
#include "common.h"
|
2006-05-08 03:20:50 +00:00
|
|
|
#include "dhcpd.h"
|
|
|
|
|
|
|
|
/* Takes the address of the pointer to the static_leases linked list,
|
2009-06-16 10:03:12 +00:00
|
|
|
* address to a 6 byte mac address,
|
|
|
|
* 4 byte IP address */
|
|
|
|
void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp,
|
|
|
|
uint8_t *mac,
|
|
|
|
uint32_t nip)
|
2006-05-08 03:20:50 +00:00
|
|
|
{
|
2009-06-16 10:03:12 +00:00
|
|
|
struct static_lease *st_lease;
|
2006-05-08 03:20:50 +00:00
|
|
|
|
2009-06-16 10:03:12 +00:00
|
|
|
/* Find the tail of the list */
|
|
|
|
while ((st_lease = *st_lease_pp) != NULL) {
|
|
|
|
st_lease_pp = &st_lease->next;
|
2006-05-08 03:20:50 +00:00
|
|
|
}
|
2009-06-16 10:03:12 +00:00
|
|
|
|
|
|
|
/* Add new node */
|
|
|
|
*st_lease_pp = st_lease = xzalloc(sizeof(*st_lease));
|
|
|
|
memcpy(st_lease->mac, mac, 6);
|
|
|
|
st_lease->nip = nip;
|
|
|
|
/*st_lease->next = NULL;*/
|
2006-05-08 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 10:03:12 +00:00
|
|
|
/* Find static lease IP by mac */
|
|
|
|
uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac)
|
2006-05-08 03:20:50 +00:00
|
|
|
{
|
2009-06-16 10:03:12 +00:00
|
|
|
while (st_lease) {
|
|
|
|
if (memcmp(st_lease->mac, mac, 6) == 0)
|
|
|
|
return st_lease->nip;
|
|
|
|
st_lease = st_lease->next;
|
2006-05-08 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 17:52:09 +00:00
|
|
|
return 0;
|
2006-05-08 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 10:03:12 +00:00
|
|
|
/* Check to see if an IP is reserved as a static IP */
|
|
|
|
int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip)
|
2006-05-08 03:20:50 +00:00
|
|
|
{
|
2009-06-16 10:03:12 +00:00
|
|
|
while (st_lease) {
|
|
|
|
if (st_lease->nip == nip)
|
2009-01-01 17:52:09 +00:00
|
|
|
return 1;
|
2009-06-16 10:03:12 +00:00
|
|
|
st_lease = st_lease->next;
|
2006-05-08 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 17:52:09 +00:00
|
|
|
return 0;
|
2006-05-08 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
2009-06-17 11:44:04 +00:00
|
|
|
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
|
2006-05-08 03:20:50 +00:00
|
|
|
/* Print out static leases just to check what's going on */
|
|
|
|
/* Takes the address of the pointer to the static_leases linked list */
|
2009-06-17 11:44:04 +00:00
|
|
|
void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp)
|
2006-05-08 03:20:50 +00:00
|
|
|
{
|
2009-06-17 11:44:04 +00:00
|
|
|
struct static_lease *cur;
|
2006-05-08 03:20:50 +00:00
|
|
|
|
2009-06-17 11:44:04 +00:00
|
|
|
if (dhcp_verbose < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cur = *st_lease_pp;
|
2006-11-18 19:51:32 +00:00
|
|
|
while (cur) {
|
2009-06-17 11:44:04 +00:00
|
|
|
bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
|
2009-01-01 17:52:09 +00:00
|
|
|
cur->mac[0], cur->mac[1], cur->mac[2],
|
2009-06-17 11:44:04 +00:00
|
|
|
cur->mac[3], cur->mac[4], cur->mac[5],
|
|
|
|
cur->nip
|
2009-01-01 17:52:09 +00:00
|
|
|
);
|
2006-05-08 03:20:50 +00:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|