mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-18 00:37:01 +00:00
analyse: critical bug in the counting code
The problem is, that you simply count all lease occurrences in dhcpd.leases, but only the last ones for each ip address are valid. The lease file is more like a logfile of what has been done, than a real database. To fix the counting issue, I'm using a single hash (from uthash.h [1]) for the counting. This way only the last lease entry for each IP gets into my counting structure. When you remove the duplicates in prepare_data(), you don't have the information anymore, if the active lease entry or the free lease entry came last. Simply deleting each ip from the touches array, that is already in the leases array, gives you a big chance to count wrong. Another way of fixing this would be to not only store the ips in your arrays, but a structure containing the ip and a global lease entry counter. Then you could delete all entries except for the latest. [1] http://uthash.sourceforge.net/ Reported-by: Huangy Signed-off-by: Enno Grper <groepeen@cms.hu-berlin.de> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
3ef5d6c07f
commit
ae7747db87
10 changed files with 166 additions and 150 deletions
|
|
@ -40,6 +40,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <uthash.h>
|
||||
|
||||
/* Feature test switches */
|
||||
#define _POSIX_SOURCE 1
|
||||
|
|
@ -122,6 +123,16 @@ struct macaddr_t {
|
|||
char *ip;
|
||||
struct macaddr_t *next;
|
||||
};
|
||||
enum ltype {
|
||||
ACTIVE,
|
||||
FREE,
|
||||
BACKUP
|
||||
};
|
||||
struct leases_t {
|
||||
uint32_t ip; /* ip as key */
|
||||
enum ltype type;
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
|
||||
/* Global variables */
|
||||
struct configuration_t config;
|
||||
|
|
@ -133,11 +144,9 @@ struct shared_network_t *shared_networks;
|
|||
unsigned int num_shared_networks;
|
||||
struct range_t *ranges;
|
||||
unsigned int num_ranges;
|
||||
uint32_t *leases;
|
||||
struct leases_t *leases;
|
||||
unsigned long int num_leases;
|
||||
uint32_t *touches;
|
||||
unsigned long int num_touches;
|
||||
uint32_t *backups;
|
||||
unsigned long int num_backups;
|
||||
struct macaddr_t *macaddr;
|
||||
|
||||
|
|
@ -200,5 +209,10 @@ int output_xml(void);
|
|||
int output_csv(void);
|
||||
/* Memory release, file closing etc */
|
||||
void clean_up(void);
|
||||
/* Hash functions */
|
||||
void add_lease(int ip, enum ltype type);
|
||||
struct leases_t * find_lease(int ip);
|
||||
void delete_lease(struct leases_t * lease);
|
||||
void delete_all_leases();
|
||||
|
||||
#endif /* DHCPD_POOLS_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue