source: MondoRescue/branches/2.2.9/mindi-busybox/networking/udhcp/static_leases.c@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.8 KB
RevLine 
[1765]1/* vi: set sw=4 ts=4: */
[821]2/*
[2725]3 * Storing and retrieving data for static leases
[821]4 *
5 * Wade Berrier <wberrier@myrealbox.com> September 2004
6 *
[2725]7 * Licensed under GPLv2, see file LICENSE in this source tree.
[821]8 */
[1765]9#include "common.h"
10#include "dhcpd.h"
[821]11
12/* Takes the address of the pointer to the static_leases linked list,
[2725]13 * address to a 6 byte mac address,
14 * 4 byte IP address */
15void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp,
16 uint8_t *mac,
17 uint32_t nip)
[821]18{
[2725]19 struct static_lease *st_lease;
[821]20
[2725]21 /* Find the tail of the list */
22 while ((st_lease = *st_lease_pp) != NULL) {
23 st_lease_pp = &st_lease->next;
[821]24 }
25
[2725]26 /* Add new node */
27 *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease));
28 memcpy(st_lease->mac, mac, 6);
29 st_lease->nip = nip;
30 /*st_lease->next = NULL;*/
[821]31}
32
[2725]33/* Find static lease IP by mac */
34uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac)
[821]35{
[2725]36 while (st_lease) {
37 if (memcmp(st_lease->mac, mac, 6) == 0)
38 return st_lease->nip;
39 st_lease = st_lease->next;
[821]40 }
41
[2725]42 return 0;
[821]43}
44
[2725]45/* Check to see if an IP is reserved as a static IP */
46int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip)
[821]47{
[2725]48 while (st_lease) {
49 if (st_lease->nip == nip)
50 return 1;
51 st_lease = st_lease->next;
[821]52 }
53
[2725]54 return 0;
[821]55}
56
[2725]57#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
[821]58/* Print out static leases just to check what's going on */
59/* Takes the address of the pointer to the static_leases linked list */
[2725]60void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp)
[821]61{
[2725]62 struct static_lease *cur;
[821]63
[2725]64 if (dhcp_verbose < 2)
65 return;
66
67 cur = *st_lease_pp;
[1765]68 while (cur) {
[2725]69 bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
70 cur->mac[0], cur->mac[1], cur->mac[2],
71 cur->mac[3], cur->mac[4], cur->mac[5],
72 cur->nip
73 );
[821]74 cur = cur->next;
75 }
76}
77#endif
Note: See TracBrowser for help on using the repository browser.