2006-07-02 19:47:05 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2006-05-08 03:20:50 +00:00
|
|
|
/*
|
|
|
|
* static_leases.c -- Couple of functions to assist with storing and
|
|
|
|
* retrieving data for static leases
|
|
|
|
*
|
|
|
|
* Wade Berrier <wberrier@myrealbox.com> September 2004
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-11-18 19:51:32 +00:00
|
|
|
#include "common.h"
|
2006-05-08 03:20:50 +00:00
|
|
|
#include "dhcpd.h"
|
|
|
|
|
2006-11-18 19:51:32 +00:00
|
|
|
|
2006-05-08 03:20:50 +00:00
|
|
|
/* 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 */
|
|
|
|
int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
|
|
|
|
{
|
|
|
|
struct static_lease *cur;
|
|
|
|
struct static_lease *new_static_lease;
|
|
|
|
|
|
|
|
/* Build new node */
|
|
|
|
new_static_lease = xmalloc(sizeof(struct static_lease));
|
|
|
|
new_static_lease->mac = mac;
|
|
|
|
new_static_lease->ip = ip;
|
|
|
|
new_static_lease->next = NULL;
|
|
|
|
|
|
|
|
/* If it's the first node to be added... */
|
2006-11-18 19:51:32 +00:00
|
|
|
if (*lease_struct == NULL) {
|
2006-05-08 03:20:50 +00:00
|
|
|
*lease_struct = new_static_lease;
|
2006-11-18 19:51:32 +00:00
|
|
|
} else {
|
2006-05-08 03:20:50 +00:00
|
|
|
cur = *lease_struct;
|
2006-11-18 19:51:32 +00:00
|
|
|
while (cur->next) {
|
2006-05-08 03:20:50 +00:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur->next = new_static_lease;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if a mac has an associated static lease */
|
|
|
|
uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
|
|
|
|
{
|
|
|
|
uint32_t return_ip;
|
|
|
|
struct static_lease *cur = lease_struct;
|
|
|
|
uint8_t *mac = arg;
|
|
|
|
|
|
|
|
return_ip = 0;
|
|
|
|
|
2006-11-18 19:51:32 +00:00
|
|
|
while (cur) {
|
2006-05-08 03:20:50 +00:00
|
|
|
/* If the client has the correct mac */
|
2006-11-18 19:51:32 +00:00
|
|
|
if (memcmp(cur->mac, mac, 6) == 0) {
|
2006-05-08 03:20:50 +00:00
|
|
|
return_ip = *(cur->ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if an ip is reserved as a static ip */
|
|
|
|
uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
|
|
|
|
{
|
|
|
|
struct static_lease *cur = lease_struct;
|
|
|
|
|
|
|
|
uint32_t return_val = 0;
|
|
|
|
|
2006-11-18 19:51:32 +00:00
|
|
|
while (cur) {
|
2006-05-08 03:20:50 +00:00
|
|
|
/* If the client has the correct ip */
|
2006-11-18 19:51:32 +00:00
|
|
|
if (*cur->ip == ip)
|
2006-05-08 03:20:50 +00:00
|
|
|
return_val = 1;
|
|
|
|
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_val;
|
|
|
|
}
|
|
|
|
|
2006-11-21 10:15:25 +00:00
|
|
|
#if ENABLE_FEATURE_UDHCP_DEBUG
|
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 */
|
|
|
|
void printStaticLeases(struct static_lease **arg)
|
|
|
|
{
|
|
|
|
/* Get a pointer to the linked list */
|
|
|
|
struct static_lease *cur = *arg;
|
|
|
|
|
2006-11-18 19:51:32 +00:00
|
|
|
while (cur) {
|
2006-05-08 03:20:50 +00:00
|
|
|
/* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
|
|
|
|
printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
|
|
|
|
/* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
|
|
|
|
printf("PrintStaticLeases: Lease ip Value: %x\n", *(cur->ip));
|
|
|
|
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|