diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-04 00:43:14 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-04 00:56:58 +0200 |
commit | d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d (patch) | |
tree | 2d1a84fe6968c657afca97a5b43bb5cc5ea5c966 /networking/udhcp/dhcpd.c | |
parent | 2bf2931d526fbd3998b9ffe99cdbad5d5ea6d290 (diff) | |
download | busybox-w32-d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d.tar.gz busybox-w32-d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d.tar.bz2 busybox-w32-d2ae66cb3e5c79ffdbde553fa6cce64f9218e14d.zip |
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 8bd65df52..b625756f9 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -39,7 +39,64 @@ | |||
39 | #include "dhcpc.h" | 39 | #include "dhcpc.h" |
40 | #include "dhcpd.h" | 40 | #include "dhcpd.h" |
41 | 41 | ||
42 | /* on these functions, make sure your datatype matches */ | 42 | /* Takes the address of the pointer to the static_leases linked list, |
43 | * address to a 6 byte mac address, | ||
44 | * 4 byte IP address */ | ||
45 | static void add_static_lease(struct static_lease **st_lease_pp, | ||
46 | uint8_t *mac, | ||
47 | uint32_t nip) | ||
48 | { | ||
49 | struct static_lease *st_lease; | ||
50 | |||
51 | /* Find the tail of the list */ | ||
52 | while ((st_lease = *st_lease_pp) != NULL) { | ||
53 | st_lease_pp = &st_lease->next; | ||
54 | } | ||
55 | |||
56 | /* Add new node */ | ||
57 | *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease)); | ||
58 | memcpy(st_lease->mac, mac, 6); | ||
59 | st_lease->nip = nip; | ||
60 | /*st_lease->next = NULL;*/ | ||
61 | } | ||
62 | |||
63 | /* Find static lease IP by mac */ | ||
64 | static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac) | ||
65 | { | ||
66 | while (st_lease) { | ||
67 | if (memcmp(st_lease->mac, mac, 6) == 0) | ||
68 | return st_lease->nip; | ||
69 | st_lease = st_lease->next; | ||
70 | } | ||
71 | |||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 | ||
76 | /* Print out static leases just to check what's going on */ | ||
77 | /* Takes the address of the pointer to the static_leases linked list */ | ||
78 | static void log_static_leases(struct static_lease **st_lease_pp) | ||
79 | { | ||
80 | struct static_lease *cur; | ||
81 | |||
82 | if (dhcp_verbose < 2) | ||
83 | return; | ||
84 | |||
85 | cur = *st_lease_pp; | ||
86 | while (cur) { | ||
87 | bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", | ||
88 | cur->mac[0], cur->mac[1], cur->mac[2], | ||
89 | cur->mac[3], cur->mac[4], cur->mac[5], | ||
90 | cur->nip | ||
91 | ); | ||
92 | cur = cur->next; | ||
93 | } | ||
94 | } | ||
95 | #else | ||
96 | # define log_static_leases(st_lease_pp) ((void)0) | ||
97 | #endif | ||
98 | |||
99 | /* On these functions, make sure your datatype matches */ | ||
43 | static int FAST_FUNC read_str(const char *line, void *arg) | 100 | static int FAST_FUNC read_str(const char *line, void *arg) |
44 | { | 101 | { |
45 | char **dest = arg; | 102 | char **dest = arg; |