diff options
author | Denys Vlasenko | 2009-06-16 12:03:12 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-06-16 12:03:12 +0200 |
commit | cab3a0127c3e6b7fc4f794ba6abcb8e01492118e (patch) | |
tree | ea04fac708ea47e251066ea6782b6f743f04933d /networking/udhcp/static_leases.c | |
parent | 56f2d06c6496e49d7e752d1ee5ac5ea420b4ed11 (diff) | |
download | busybox-cab3a0127c3e6b7fc4f794ba6abcb8e01492118e.zip busybox-cab3a0127c3e6b7fc4f794ba6abcb8e01492118e.tar.gz |
udhcp: cleanup of static lease handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/static_leases.c')
-rw-r--r-- | networking/udhcp/static_leases.c | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c index 1e77a58..7d1aa2f 100644 --- a/networking/udhcp/static_leases.c +++ b/networking/udhcp/static_leases.c @@ -13,48 +13,45 @@ /* 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 */ -void FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t ip) + * 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) { - struct static_lease *new_static_lease; + struct static_lease *st_lease; - /* Build new node */ - new_static_lease = xzalloc(sizeof(struct static_lease)); - memcpy(new_static_lease->mac, mac, 6); - 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 { - struct static_lease *cur = *lease_struct; - while (cur->next) - cur = cur->next; - cur->next = new_static_lease; + /* Find the tail of the list */ + while ((st_lease = *st_lease_pp) != NULL) { + st_lease_pp = &st_lease->next; } + + /* 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;*/ } -/* Check to see if a mac has an associated static lease */ -uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *mac) +/* Find static lease IP by mac */ +uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac) { - while (lease_struct) { - if (memcmp(lease_struct->mac, mac, 6) == 0) - return lease_struct->ip; - lease_struct = lease_struct->next; + while (st_lease) { + if (memcmp(st_lease->mac, mac, 6) == 0) + return st_lease->nip; + st_lease = st_lease->next; } return 0; } -/* Check to see if an ip is reserved as a static ip */ -int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip) +/* 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) { - while (lease_struct) { - if (lease_struct->ip == ip) + while (st_lease) { + if (st_lease->nip == nip) return 1; - lease_struct = lease_struct->next; + st_lease = st_lease->next; } return 0; @@ -63,16 +60,16 @@ int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip) #if ENABLE_UDHCP_DEBUG /* Print out static leases just to check what's going on */ /* Takes the address of the pointer to the static_leases linked list */ -void FAST_FUNC printStaticLeases(struct static_lease **arg) +void FAST_FUNC print_static_leases(struct static_lease **st_lease_pp) { - struct static_lease *cur = *arg; + struct static_lease *cur = *st_lease_pp; while (cur) { - printf("PrintStaticLeases: Lease mac Value: %02x:%02x:%02x:%02x:%02x:%02x\n", + printf("PrintStaticLeases: lease mac: %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); + printf("PrintStaticLeases: lease ip: %x\n", cur->nip); cur = cur->next; } } |