5 |
* |
* |
6 |
* Wade Berrier <wberrier@myrealbox.com> September 2004 |
* Wade Berrier <wberrier@myrealbox.com> September 2004 |
7 |
* |
* |
8 |
|
* Licensed under GPLv2, see file LICENSE in this tarball for details. |
9 |
*/ |
*/ |
10 |
|
|
11 |
#include "common.h" |
#include "common.h" |
13 |
|
|
14 |
|
|
15 |
/* Takes the address of the pointer to the static_leases linked list, |
/* Takes the address of the pointer to the static_leases linked list, |
16 |
* Address to a 6 byte mac address |
* address to a 6 byte mac address, |
17 |
* Address to a 4 byte ip address */ |
* 4 byte IP address */ |
18 |
int FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip) |
void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp, |
19 |
|
uint8_t *mac, |
20 |
|
uint32_t nip) |
21 |
{ |
{ |
22 |
struct static_lease *cur; |
struct static_lease *st_lease; |
|
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... */ |
|
|
if (*lease_struct == NULL) { |
|
|
*lease_struct = new_static_lease; |
|
|
} else { |
|
|
cur = *lease_struct; |
|
|
while (cur->next) { |
|
|
cur = cur->next; |
|
|
} |
|
23 |
|
|
24 |
cur->next = new_static_lease; |
/* Find the tail of the list */ |
25 |
|
while ((st_lease = *st_lease_pp) != NULL) { |
26 |
|
st_lease_pp = &st_lease->next; |
27 |
} |
} |
28 |
|
|
29 |
return 1; |
/* Add new node */ |
30 |
|
*st_lease_pp = st_lease = xzalloc(sizeof(*st_lease)); |
31 |
|
memcpy(st_lease->mac, mac, 6); |
32 |
|
st_lease->nip = nip; |
33 |
|
/*st_lease->next = NULL;*/ |
34 |
} |
} |
35 |
|
|
36 |
/* Check to see if a mac has an associated static lease */ |
/* Find static lease IP by mac */ |
37 |
uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *arg) |
uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac) |
38 |
{ |
{ |
39 |
uint32_t return_ip; |
while (st_lease) { |
40 |
struct static_lease *cur = lease_struct; |
if (memcmp(st_lease->mac, mac, 6) == 0) |
41 |
uint8_t *mac = arg; |
return st_lease->nip; |
42 |
|
st_lease = st_lease->next; |
|
return_ip = 0; |
|
|
|
|
|
while (cur) { |
|
|
/* If the client has the correct mac */ |
|
|
if (memcmp(cur->mac, mac, 6) == 0) { |
|
|
return_ip = *(cur->ip); |
|
|
} |
|
|
|
|
|
cur = cur->next; |
|
43 |
} |
} |
44 |
|
|
45 |
return return_ip; |
return 0; |
46 |
} |
} |
47 |
|
|
48 |
/* Check to see if an ip is reserved as a static ip */ |
/* Check to see if an IP is reserved as a static IP */ |
49 |
uint32_t FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip) |
int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip) |
50 |
{ |
{ |
51 |
struct static_lease *cur = lease_struct; |
while (st_lease) { |
52 |
|
if (st_lease->nip == nip) |
53 |
uint32_t return_val = 0; |
return 1; |
54 |
|
st_lease = st_lease->next; |
|
while (cur) { |
|
|
/* If the client has the correct ip */ |
|
|
if (*cur->ip == ip) |
|
|
return_val = 1; |
|
|
|
|
|
cur = cur->next; |
|
55 |
} |
} |
56 |
|
|
57 |
return return_val; |
return 0; |
58 |
} |
} |
59 |
|
|
60 |
#if ENABLE_UDHCP_DEBUG |
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 |
61 |
/* Print out static leases just to check what's going on */ |
/* Print out static leases just to check what's going on */ |
62 |
/* Takes the address of the pointer to the static_leases linked list */ |
/* Takes the address of the pointer to the static_leases linked list */ |
63 |
void FAST_FUNC printStaticLeases(struct static_lease **arg) |
void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp) |
64 |
{ |
{ |
65 |
/* Get a pointer to the linked list */ |
struct static_lease *cur; |
|
struct static_lease *cur = *arg; |
|
66 |
|
|
67 |
while (cur) { |
if (dhcp_verbose < 2) |
68 |
/* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */ |
return; |
|
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)); |
|
69 |
|
|
70 |
|
cur = *st_lease_pp; |
71 |
|
while (cur) { |
72 |
|
bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", |
73 |
|
cur->mac[0], cur->mac[1], cur->mac[2], |
74 |
|
cur->mac[3], cur->mac[4], cur->mac[5], |
75 |
|
cur->nip |
76 |
|
); |
77 |
cur = cur->next; |
cur = cur->next; |
78 |
} |
} |
79 |
} |
} |