2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2006-05-08 08:50:50 +05:30
|
|
|
/*
|
|
|
|
* static_leases.c -- Couple of functions to assist with storing and
|
|
|
|
* retrieving data for static leases
|
|
|
|
*
|
|
|
|
* Wade Berrier <wberrier@myrealbox.com> September 2004
|
|
|
|
*
|
2008-12-07 06:22:58 +05:30
|
|
|
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
2006-05-08 08:50:50 +05:30
|
|
|
*/
|
|
|
|
|
2006-11-19 01:21:32 +05:30
|
|
|
#include "common.h"
|
2006-05-08 08:50:50 +05:30
|
|
|
#include "dhcpd.h"
|
|
|
|
|
2006-11-19 01:21:32 +05:30
|
|
|
|
2006-05-08 08:50:50 +05:30
|
|
|
/* Takes the address of the pointer to the static_leases linked list,
|
2009-06-16 15:33:12 +05:30
|
|
|
* 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 08:50:50 +05:30
|
|
|
{
|
2009-06-16 15:33:12 +05:30
|
|
|
struct static_lease *st_lease;
|
2006-05-08 08:50:50 +05:30
|
|
|
|
2009-06-16 15:33:12 +05:30
|
|
|
/* Find the tail of the list */
|
|
|
|
while ((st_lease = *st_lease_pp) != NULL) {
|
|
|
|
st_lease_pp = &st_lease->next;
|
2006-05-08 08:50:50 +05:30
|
|
|
}
|
2009-06-16 15:33:12 +05:30
|
|
|
|
|
|
|
/* 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 08:50:50 +05:30
|
|
|
}
|
|
|
|
|
2009-06-16 15:33:12 +05:30
|
|
|
/* 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 08:50:50 +05:30
|
|
|
{
|
2009-06-16 15:33:12 +05:30
|
|
|
while (st_lease) {
|
|
|
|
if (memcmp(st_lease->mac, mac, 6) == 0)
|
|
|
|
return st_lease->nip;
|
|
|
|
st_lease = st_lease->next;
|
2006-05-08 08:50:50 +05:30
|
|
|
}
|
|
|
|
|
2009-01-01 23:22:09 +05:30
|
|
|
return 0;
|
2006-05-08 08:50:50 +05:30
|
|
|
}
|
|
|
|
|
2009-06-16 15:33:12 +05:30
|
|
|
/* 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 08:50:50 +05:30
|
|
|
{
|
2009-06-16 15:33:12 +05:30
|
|
|
while (st_lease) {
|
|
|
|
if (st_lease->nip == nip)
|
2009-01-01 23:22:09 +05:30
|
|
|
return 1;
|
2009-06-16 15:33:12 +05:30
|
|
|
st_lease = st_lease->next;
|
2006-05-08 08:50:50 +05:30
|
|
|
}
|
|
|
|
|
2009-01-01 23:22:09 +05:30
|
|
|
return 0;
|
2006-05-08 08:50:50 +05:30
|
|
|
}
|
|
|
|
|
2008-11-06 06:19:59 +05:30
|
|
|
#if ENABLE_UDHCP_DEBUG
|
2006-05-08 08:50:50 +05:30
|
|
|
/* 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-16 15:33:12 +05:30
|
|
|
void FAST_FUNC print_static_leases(struct static_lease **st_lease_pp)
|
2006-05-08 08:50:50 +05:30
|
|
|
{
|
2009-06-16 15:33:12 +05:30
|
|
|
struct static_lease *cur = *st_lease_pp;
|
2006-05-08 08:50:50 +05:30
|
|
|
|
2006-11-19 01:21:32 +05:30
|
|
|
while (cur) {
|
2009-06-16 15:33:12 +05:30
|
|
|
printf("PrintStaticLeases: lease mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
2009-01-01 23:22:09 +05:30
|
|
|
cur->mac[0], cur->mac[1], cur->mac[2],
|
|
|
|
cur->mac[3], cur->mac[4], cur->mac[5]
|
|
|
|
);
|
2009-06-16 15:33:12 +05:30
|
|
|
printf("PrintStaticLeases: lease ip: %x\n", cur->nip);
|
2006-05-08 08:50:50 +05:30
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|