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>
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;