diff options
author | Denys Vlasenko | 2016-10-04 00:43:14 +0200 |
---|---|---|
committer | Denys Vlasenko | 2016-10-04 00:56:58 +0200 |
commit | d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d (patch) | |
tree | 2d1a84fe6968c657afca97a5b43bb5cc5ea5c966 /networking/udhcp/dhcpd.c | |
parent | 2bf2931d526fbd3998b9ffe99cdbad5d5ea6d290 (diff) | |
download | busybox-d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d.zip busybox-d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d.tar.gz |
dhcp: merge most of static_leases.c into dhcpd.c
function old new delta
read_staticlease 121 222 +101
add_static_lease 48 - -48
log_static_leases 68 - -68
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 101/-116) Total: -15 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpd.c')
-rw-r--r-- | networking/udhcp/dhcpd.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 8bd65df..b625756 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -39,7 +39,64 @@ #include "dhcpc.h" #include "dhcpd.h" -/* on these functions, make sure your datatype matches */ +/* Takes the address of the pointer to the static_leases linked list, + * address to a 6 byte mac address, + * 4 byte IP address */ +static void add_static_lease(struct static_lease **st_lease_pp, + uint8_t *mac, + uint32_t nip) +{ + struct static_lease *st_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;*/ +} + +/* Find static lease IP by mac */ +static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac) +{ + while (st_lease) { + if (memcmp(st_lease->mac, mac, 6) == 0) + return st_lease->nip; + st_lease = st_lease->next; + } + + return 0; +} + +#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 +/* Print out static leases just to check what's going on */ +/* Takes the address of the pointer to the static_leases linked list */ +static void log_static_leases(struct static_lease **st_lease_pp) +{ + struct static_lease *cur; + + if (dhcp_verbose < 2) + return; + + cur = *st_lease_pp; + while (cur) { + bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", + cur->mac[0], cur->mac[1], cur->mac[2], + cur->mac[3], cur->mac[4], cur->mac[5], + cur->nip + ); + cur = cur->next; + } +} +#else +# define log_static_leases(st_lease_pp) ((void)0) +#endif + +/* On these functions, make sure your datatype matches */ static int FAST_FUNC read_str(const char *line, void *arg) { char **dest = arg; |