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 | |
| 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>
| -rw-r--r-- | networking/udhcp/dhcpd.c | 59 | ||||
| -rw-r--r-- | networking/udhcp/dhcpd.h | 13 | ||||
| -rw-r--r-- | networking/udhcp/static_leases.c | 55 |
3 files changed, 58 insertions, 69 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; |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 08c9e8c63..b8d94a763 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
| @@ -102,20 +102,7 @@ struct dyn_lease *find_lease_by_mac(const uint8_t *mac) FAST_FUNC; | |||
| 102 | struct dyn_lease *find_lease_by_nip(uint32_t nip) FAST_FUNC; | 102 | struct dyn_lease *find_lease_by_nip(uint32_t nip) FAST_FUNC; |
| 103 | uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arpping_ms) FAST_FUNC; | 103 | uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arpping_ms) FAST_FUNC; |
| 104 | 104 | ||
| 105 | |||
| 106 | /* Config file parser will pass static lease info to this function | ||
| 107 | * which will add it to a data structure that can be searched later */ | ||
| 108 | void add_static_lease(struct static_lease **st_lease_pp, uint8_t *mac, uint32_t nip) FAST_FUNC; | ||
| 109 | /* Find static lease IP by mac */ | ||
| 110 | uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *arg) FAST_FUNC; | ||
| 111 | /* Check to see if an IP is reserved as a static IP */ | ||
| 112 | int is_nip_reserved(struct static_lease *st_lease, uint32_t nip) FAST_FUNC; | 105 | int is_nip_reserved(struct static_lease *st_lease, uint32_t nip) FAST_FUNC; |
| 113 | /* Print out static leases just to check what's going on (debug code) */ | ||
| 114 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 | ||
| 115 | void log_static_leases(struct static_lease **st_lease_pp) FAST_FUNC; | ||
| 116 | #else | ||
| 117 | # define log_static_leases(st_lease_pp) ((void)0) | ||
| 118 | #endif | ||
| 119 | 106 | ||
| 120 | POP_SAVED_FUNCTION_VISIBILITY | 107 | POP_SAVED_FUNCTION_VISIBILITY |
| 121 | 108 | ||
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c index b7f9e5c59..3be7a5228 100644 --- a/networking/udhcp/static_leases.c +++ b/networking/udhcp/static_leases.c | |||
| @@ -9,39 +9,6 @@ | |||
| 9 | #include "common.h" | 9 | #include "common.h" |
| 10 | #include "dhcpd.h" | 10 | #include "dhcpd.h" |
| 11 | 11 | ||
| 12 | /* Takes the address of the pointer to the static_leases linked list, | ||
| 13 | * address to a 6 byte mac address, | ||
| 14 | * 4 byte IP address */ | ||
| 15 | void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp, | ||
| 16 | uint8_t *mac, | ||
| 17 | uint32_t nip) | ||
| 18 | { | ||
| 19 | struct static_lease *st_lease; | ||
| 20 | |||
| 21 | /* Find the tail of the list */ | ||
| 22 | while ((st_lease = *st_lease_pp) != NULL) { | ||
| 23 | st_lease_pp = &st_lease->next; | ||
| 24 | } | ||
| 25 | |||
| 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;*/ | ||
| 31 | } | ||
| 32 | |||
| 33 | /* Find static lease IP by mac */ | ||
| 34 | uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac) | ||
| 35 | { | ||
| 36 | while (st_lease) { | ||
| 37 | if (memcmp(st_lease->mac, mac, 6) == 0) | ||
| 38 | return st_lease->nip; | ||
| 39 | st_lease = st_lease->next; | ||
| 40 | } | ||
| 41 | |||
| 42 | return 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | /* Check to see if an IP is reserved as a static IP */ | 12 | /* Check to see if an IP is reserved as a static IP */ |
| 46 | int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip) | 13 | int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip) |
| 47 | { | 14 | { |
| @@ -53,25 +20,3 @@ int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip) | |||
| 53 | 20 | ||
| 54 | return 0; | 21 | return 0; |
| 55 | } | 22 | } |
| 56 | |||
| 57 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 | ||
| 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 */ | ||
| 60 | void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp) | ||
| 61 | { | ||
| 62 | struct static_lease *cur; | ||
| 63 | |||
| 64 | if (dhcp_verbose < 2) | ||
| 65 | return; | ||
| 66 | |||
| 67 | cur = *st_lease_pp; | ||
| 68 | while (cur) { | ||
| 69 | bb_error_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 | ); | ||
| 74 | cur = cur->next; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | #endif | ||
