Wade Berrier writes:
Hello, Here's a patch for a first attempt at static leases for udhcpd. Included in the tarball are 2 files (static_leases.c, static_leases.h) and a patch against the latest cvs. In the config file you can configure static leases with the following format: static_lease 00:60:08:11:CE:4E 192.168.0.54 static_lease 00:60:08:11:CE:3E 192.168.0.44 Comments/suggestions/improvements are welcome. Wade
This commit is contained in:
@ -11,6 +11,9 @@
|
||||
#include <ctype.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <netinet/ether.h>
|
||||
#include "static_leases.h"
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include "files.h"
|
||||
#include "options.h"
|
||||
@ -38,6 +41,22 @@ static int read_ip(const char *line, void *arg)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int read_mac(const char *line, void *arg)
|
||||
{
|
||||
uint8_t *mac_bytes = arg;
|
||||
struct ether_addr *temp_ether_addr;
|
||||
int retval = 1;
|
||||
|
||||
temp_ether_addr = ether_aton(line);
|
||||
|
||||
if(temp_ether_addr == NULL)
|
||||
retval = 0;
|
||||
else
|
||||
memcpy(mac_bytes, temp_ether_addr, 6);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static int read_str(const char *line, void *arg)
|
||||
{
|
||||
@ -150,6 +169,39 @@ static int read_opt(const char *const_line, void *arg)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int read_staticlease(const char *const_line, void *arg)
|
||||
{
|
||||
|
||||
char *line;
|
||||
char *mac_string;
|
||||
char *ip_string;
|
||||
uint8_t *mac_bytes;
|
||||
uint32_t *ip;
|
||||
|
||||
|
||||
/* Allocate memory for addresses */
|
||||
mac_bytes = xmalloc(sizeof(unsigned char) * 8);
|
||||
ip = xmalloc(sizeof(uint32_t));
|
||||
|
||||
/* Read mac */
|
||||
line = (char *) const_line;
|
||||
mac_string = strtok(line, " \t");
|
||||
read_mac(mac_string, mac_bytes);
|
||||
|
||||
/* Read ip */
|
||||
ip_string = strtok(NULL, " \t");
|
||||
read_ip(ip_string, ip);
|
||||
|
||||
addStaticLease(arg, mac_bytes, ip);
|
||||
|
||||
#ifdef UDHCP_DEBUG
|
||||
printStaticLeases(arg);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static const struct config_keyword keywords[] = {
|
||||
/* keyword handler variable address default */
|
||||
@ -171,6 +223,7 @@ static const struct config_keyword keywords[] = {
|
||||
{"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"},
|
||||
{"sname", read_str, &(server_config.sname), ""},
|
||||
{"boot_file", read_str, &(server_config.boot_file), ""},
|
||||
{"static_lease",read_staticlease, &(server_config.static_leases), ""},
|
||||
/*ADDME: static lease */
|
||||
{"", NULL, NULL, ""}
|
||||
};
|
||||
|
Reference in New Issue
Block a user