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,
|
|
|
|
* Address to a 6 byte mac address
|
|
|
|
* Address to a 4 byte ip address */
|
2009-01-01 23:22:09 +05:30
|
|
|
void FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t ip)
|
2006-05-08 08:50:50 +05:30
|
|
|
{
|
|
|
|
struct static_lease *new_static_lease;
|
|
|
|
|
|
|
|
/* Build new node */
|
2009-01-01 23:22:09 +05:30
|
|
|
new_static_lease = xzalloc(sizeof(struct static_lease));
|
|
|
|
memcpy(new_static_lease->mac, mac, 6);
|
2006-05-08 08:50:50 +05:30
|
|
|
new_static_lease->ip = ip;
|
2009-01-01 23:22:09 +05:30
|
|
|
/*new_static_lease->next = NULL;*/
|
2006-05-08 08:50:50 +05:30
|
|
|
|
|
|
|
/* If it's the first node to be added... */
|
2006-11-19 01:21:32 +05:30
|
|
|
if (*lease_struct == NULL) {
|
2006-05-08 08:50:50 +05:30
|
|
|
*lease_struct = new_static_lease;
|
2006-11-19 01:21:32 +05:30
|
|
|
} else {
|
2009-01-01 23:22:09 +05:30
|
|
|
struct static_lease *cur = *lease_struct;
|
|
|
|
while (cur->next)
|
2006-05-08 08:50:50 +05:30
|
|
|
cur = cur->next;
|
|
|
|
cur->next = new_static_lease;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if a mac has an associated static lease */
|
2009-01-01 23:22:09 +05:30
|
|
|
uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *mac)
|
2006-05-08 08:50:50 +05:30
|
|
|
{
|
2009-01-01 23:22:09 +05:30
|
|
|
while (lease_struct) {
|
|
|
|
if (memcmp(lease_struct->mac, mac, 6) == 0)
|
|
|
|
return lease_struct->ip;
|
|
|
|
lease_struct = lease_struct->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
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if an ip is reserved as a static ip */
|
2009-01-01 23:22:09 +05:30
|
|
|
int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip)
|
2006-05-08 08:50:50 +05:30
|
|
|
{
|
2009-01-01 23:22:09 +05:30
|
|
|
while (lease_struct) {
|
|
|
|
if (lease_struct->ip == ip)
|
|
|
|
return 1;
|
|
|
|
lease_struct = lease_struct->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 */
|
2008-09-26 15:04:59 +05:30
|
|
|
void FAST_FUNC printStaticLeases(struct static_lease **arg)
|
2006-05-08 08:50:50 +05:30
|
|
|
{
|
|
|
|
struct static_lease *cur = *arg;
|
|
|
|
|
2006-11-19 01:21:32 +05:30
|
|
|
while (cur) {
|
2009-01-01 23:22:09 +05:30
|
|
|
printf("PrintStaticLeases: Lease mac Value: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
cur->mac[0], cur->mac[1], cur->mac[2],
|
|
|
|
cur->mac[3], cur->mac[4], cur->mac[5]
|
|
|
|
);
|
|
|
|
printf("PrintStaticLeases: Lease ip Value: %x\n", cur->ip);
|
2006-05-08 08:50:50 +05:30
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|