udhcp: rename sprintip to sprint_nip, siaddr to siaddr_nip

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-06-16 10:25:35 +02:00
parent 990a617edf
commit 56f2d06c64
5 changed files with 26 additions and 33 deletions

View File

@ -34,13 +34,13 @@ struct dhcpMessage {
#define BROADCAST_FLAG 0x8000 /* "I need broadcast replies" */ #define BROADCAST_FLAG 0x8000 /* "I need broadcast replies" */
uint32_t ciaddr; /* client IP (if client is in BOUND, RENEW or REBINDING state) */ uint32_t ciaddr; /* client IP (if client is in BOUND, RENEW or REBINDING state) */
uint32_t yiaddr; /* 'your' (client) IP address */ uint32_t yiaddr; /* 'your' (client) IP address */
uint32_t siaddr; /* IP address of next server to use in bootstrap, /* IP address of next server to use in bootstrap, returned in DHCPOFFER, DHCPACK by server */
* returned in DHCPOFFER, DHCPACK by server */ uint32_t siaddr_nip;
uint32_t gateway_nip; /* relay agent IP address */ uint32_t gateway_nip; /* relay agent IP address */
uint8_t chaddr[16];/* link-layer client hardware address (MAC) */ uint8_t chaddr[16]; /* link-layer client hardware address (MAC) */
uint8_t sname[64]; /* server host name (ASCIZ) */ uint8_t sname[64]; /* server host name (ASCIZ) */
uint8_t file[128]; /* boot file name (ASCIZ) */ uint8_t file[128]; /* boot file name (ASCIZ) */
uint32_t cookie; /* fixed first four option bytes (99,130,83,99 dec) */ uint32_t cookie; /* fixed first four option bytes (99,130,83,99 dec) */
uint8_t options[DHCP_OPTIONS_BUFSIZE + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS]; uint8_t options[DHCP_OPTIONS_BUFSIZE + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS];
} PACKED; } PACKED;

View File

@ -39,11 +39,6 @@ struct server_config_t {
char *interface; /* The name of the interface to use */ char *interface; /* The name of the interface to use */
int ifindex; /* Index number of the interface to use */ int ifindex; /* Index number of the interface to use */
uint8_t arp[6]; /* Our arp address */ uint8_t arp[6]; /* Our arp address */
// disabled: dumpleases has no way of knowing this value,
// and will break if it's off. Now it's on always.
// char remaining; /* Should the lease time in lease file
// * be written as lease time remaining, or
// * as the absolute time the lease expires */
uint32_t lease; /* lease time in seconds (host order) */ uint32_t lease; /* lease time in seconds (host order) */
uint32_t max_leases; /* maximum number of leases (including reserved address) */ uint32_t max_leases; /* maximum number of leases (including reserved address) */
uint32_t auto_time; /* how long should udhcpd wait before writing a config file. uint32_t auto_time; /* how long should udhcpd wait before writing a config file.
@ -53,7 +48,7 @@ struct server_config_t {
uint32_t conflict_time; /* how long an arp conflict offender is leased for */ uint32_t conflict_time; /* how long an arp conflict offender is leased for */
uint32_t offer_time; /* how long an offered address is reserved */ uint32_t offer_time; /* how long an offered address is reserved */
uint32_t min_lease; /* minimum lease time a client can request */ uint32_t min_lease; /* minimum lease time a client can request */
uint32_t siaddr; /* next server bootp option */ uint32_t siaddr_nip; /* next server bootp option */
char *lease_file; char *lease_file;
char *pidfile; char *pidfile;
char *notify_file; /* What to run whenever leases are written */ char *notify_file; /* What to run whenever leases are written */
@ -81,11 +76,9 @@ struct dhcpOfferedAddr {
uint8_t lease_mac16[16]; uint8_t lease_mac16[16];
/* "nip": IP in network order */ /* "nip": IP in network order */
uint32_t lease_nip; uint32_t lease_nip;
/* Unix time when lease expires, regardless of value of /* Unix time when lease expires. Kept in memory in host order.
* server_config.remaining. Kept in memory in host order.
* When written to file, converted to network order * When written to file, converted to network order
* and optionally adjusted (current time subtracted) * and adjusted (current time subtracted) */
* if server_config.remaining = 1 */
leasetime_t expires; leasetime_t expires;
uint8_t hostname[20]; /* (size is a multiply of 4) */ uint8_t hostname[20]; /* (size is a multiply of 4) */
}; };

View File

@ -24,7 +24,7 @@ static inline uint64_t hton64(uint64_t v)
/* on these functions, make sure your datatype matches */ /* on these functions, make sure your datatype matches */
static int FAST_FUNC read_ip(const char *line, void *arg) static int FAST_FUNC read_nip(const char *line, void *arg)
{ {
len_and_sockaddr *lsa; len_and_sockaddr *lsa;
@ -187,15 +187,15 @@ static int FAST_FUNC read_opt(const char *const_line, void *arg)
opt = buffer; /* new meaning for variable opt */ opt = buffer; /* new meaning for variable opt */
switch (option->flags & TYPE_MASK) { switch (option->flags & TYPE_MASK) {
case OPTION_IP: case OPTION_IP:
retval = read_ip(val, buffer); retval = read_nip(val, buffer);
break; break;
case OPTION_IP_PAIR: case OPTION_IP_PAIR:
retval = read_ip(val, buffer); retval = read_nip(val, buffer);
val = strtok(NULL, ", \t/-"); val = strtok(NULL, ", \t/-");
if (!val) if (!val)
retval = 0; retval = 0;
if (retval) if (retval)
retval = read_ip(val, buffer + 4); retval = read_nip(val, buffer + 4);
break; break;
case OPTION_STRING: case OPTION_STRING:
#if ENABLE_FEATURE_UDHCP_RFC3397 #if ENABLE_FEATURE_UDHCP_RFC3397
@ -266,7 +266,7 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
/* Read ip */ /* Read ip */
ip_string = strtok_r(NULL, " \t", &line); ip_string = strtok_r(NULL, " \t", &line);
read_ip(ip_string, &ip); read_nip(ip_string, &ip);
addStaticLease(arg, (uint8_t*) &mac_bytes, ip); addStaticLease(arg, (uint8_t*) &mac_bytes, ip);
@ -285,13 +285,12 @@ struct config_keyword {
static const struct config_keyword keywords[] = { static const struct config_keyword keywords[] = {
/* keyword handler variable address default */ /* keyword handler variable address default */
{"start", read_ip, &(server_config.start_ip), "192.168.0.20"}, {"start", read_nip, &(server_config.start_ip), "192.168.0.20"},
{"end", read_ip, &(server_config.end_ip), "192.168.0.254"}, {"end", read_nip, &(server_config.end_ip), "192.168.0.254"},
{"interface", read_str, &(server_config.interface), "eth0"}, {"interface", read_str, &(server_config.interface), "eth0"},
/* Avoid "max_leases value not sane" warning by setting default /* Avoid "max_leases value not sane" warning by setting default
* to default_end_ip - default_start_ip + 1: */ * to default_end_ip - default_start_ip + 1: */
{"max_leases", read_u32, &(server_config.max_leases), "235"}, {"max_leases", read_u32, &(server_config.max_leases), "235"},
// {"remaining", read_yn, &(server_config.remaining), "yes"},
{"auto_time", read_u32, &(server_config.auto_time), "7200"}, {"auto_time", read_u32, &(server_config.auto_time), "7200"},
{"decline_time", read_u32, &(server_config.decline_time), "3600"}, {"decline_time", read_u32, &(server_config.decline_time), "3600"},
{"conflict_time",read_u32, &(server_config.conflict_time),"3600"}, {"conflict_time",read_u32, &(server_config.conflict_time),"3600"},
@ -299,7 +298,7 @@ static const struct config_keyword keywords[] = {
{"min_lease", read_u32, &(server_config.min_lease), "60"}, {"min_lease", read_u32, &(server_config.min_lease), "60"},
{"lease_file", read_str, &(server_config.lease_file), LEASES_FILE}, {"lease_file", read_str, &(server_config.lease_file), LEASES_FILE},
{"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"}, {"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"},
{"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"}, {"siaddr", read_nip, &(server_config.siaddr_nip), "0.0.0.0"},
/* keywords with no defaults must be last! */ /* keywords with no defaults must be last! */
{"option", read_opt, &(server_config.options), ""}, {"option", read_opt, &(server_config.options), ""},
{"opt", read_opt, &(server_config.options), ""}, {"opt", read_opt, &(server_config.options), ""},

View File

@ -37,7 +37,8 @@ static inline int upper_length(int length, int opt_index)
} }
static int sprintip(char *dest, const char *pre, const uint8_t *ip) /* note: ip is a pointer to an IP in network order, possibly misaliged */
static int sprint_nip(char *dest, const char *pre, const uint8_t *ip)
{ {
return sprintf(dest, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]); return sprintf(dest, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]);
} }
@ -76,12 +77,12 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p,
for (;;) { for (;;) {
switch (type) { switch (type) {
case OPTION_IP_PAIR: case OPTION_IP_PAIR:
dest += sprintip(dest, "", option); dest += sprint_nip(dest, "", option);
*dest++ = '/'; *dest++ = '/';
option += 4; option += 4;
optlen = 4; optlen = 4;
case OPTION_IP: /* Works regardless of host byte order. */ case OPTION_IP: /* Works regardless of host byte order. */
dest += sprintip(dest, "", option); dest += sprint_nip(dest, "", option);
break; break;
case OPTION_BOOLEAN: case OPTION_BOOLEAN:
dest += sprintf(dest, *option ? "yes" : "no"); dest += sprintf(dest, *option ? "yes" : "no");
@ -145,7 +146,7 @@ static char **fill_envp(struct dhcpMessage *packet)
num_options++; /* for mton */ num_options++; /* for mton */
} }
} }
if (packet->siaddr) if (packet->siaddr_nip)
num_options++; num_options++;
temp = get_option(packet, DHCP_OPTION_OVERLOAD); temp = get_option(packet, DHCP_OPTION_OVERLOAD);
if (temp) if (temp)
@ -164,7 +165,7 @@ static char **fill_envp(struct dhcpMessage *packet)
return envp; return envp;
*curr = xmalloc(sizeof("ip=255.255.255.255")); *curr = xmalloc(sizeof("ip=255.255.255.255"));
sprintip(*curr, "ip=", (uint8_t *) &packet->yiaddr); sprint_nip(*curr, "ip=", (uint8_t *) &packet->yiaddr);
putenv(*curr++); putenv(*curr++);
opt_name = dhcp_option_strings; opt_name = dhcp_option_strings;
@ -187,9 +188,9 @@ static char **fill_envp(struct dhcpMessage *packet)
opt_name += strlen(opt_name) + 1; opt_name += strlen(opt_name) + 1;
i++; i++;
} }
if (packet->siaddr) { if (packet->siaddr_nip) {
*curr = xmalloc(sizeof("siaddr=255.255.255.255")); *curr = xmalloc(sizeof("siaddr=255.255.255.255"));
sprintip(*curr, "siaddr=", (uint8_t *) &packet->siaddr); sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip);
putenv(*curr++); putenv(*curr++);
} }
if (!(over & FILE_FIELD) && packet->file[0]) { if (!(over & FILE_FIELD) && packet->file[0]) {

View File

@ -99,7 +99,7 @@ static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacke
/* add in the bootp options */ /* add in the bootp options */
static void add_bootp_options(struct dhcpMessage *packet) static void add_bootp_options(struct dhcpMessage *packet)
{ {
packet->siaddr = server_config.siaddr; packet->siaddr_nip = server_config.siaddr_nip;
if (server_config.sname) if (server_config.sname)
strncpy((char*)packet->sname, server_config.sname, sizeof(packet->sname) - 1); strncpy((char*)packet->sname, server_config.sname, sizeof(packet->sname) - 1);
if (server_config.boot_file) if (server_config.boot_file)