summaryrefslogtreecommitdiff
path: root/networking/udhcp/leases.c
diff options
context:
space:
mode:
authorDenis Vlasenko2009-04-01 12:36:09 +0000
committerDenis Vlasenko2009-04-01 12:36:09 +0000
commitbd79c3d337304a96dcce4ae4f97b36143919af10 (patch)
tree75115aadc65ea14c8b038be883abfe74ca5f4ced /networking/udhcp/leases.c
parent3266aa9ec285dbcf254daa17c103bf69dc755967 (diff)
downloadbusybox-bd79c3d337304a96dcce4ae4f97b36143919af10.zip
busybox-bd79c3d337304a96dcce4ae4f97b36143919af10.tar.gz
dhcpd: remember and record hostnames; optimize get_option
dumpleases: show hostnames function old new delta add_lease 230 292 +62 send_offer 403 421 +18 send_ACK 232 249 +17 read_leases 249 258 +9 dumpleases_main 604 609 +5 nobody_responds_to_arp 84 86 +2 udhcp_end_option 32 30 -2 udhcp_get_option 222 171 -51 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/2 up/down: 113/-53) Total: 60 bytes
Diffstat (limited to 'networking/udhcp/leases.c')
-rw-r--r--networking/udhcp/leases.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index 3044c20..d62f324 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -48,9 +48,12 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr)
/* Add a lease into the table, clearing out any old ones */
-struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime)
+struct dhcpOfferedAddr* FAST_FUNC add_lease(
+ const uint8_t *chaddr, uint32_t yiaddr,
+ leasetime_t leasetime, uint8_t *hostname)
{
struct dhcpOfferedAddr *oldest;
+ uint8_t hostname_length;
/* clean out any old ones */
clear_lease(chaddr, yiaddr);
@@ -58,6 +61,19 @@ struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiad
oldest = oldest_expired_lease();
if (oldest) {
+ oldest->hostname[0] = '\0';
+ if (hostname) {
+ hostname_length = hostname[-1]; /* look at option size byte */
+ if (hostname_length > sizeof(oldest->hostname))
+ hostname_length = sizeof(oldest->hostname);
+ hostname = (uint8_t*) safe_strncpy((char*)oldest->hostname, (char*)hostname, hostname_length);
+ /* sanitization (s/non-ACSII/^/g) */
+ while (*hostname) {
+ if (*hostname < ' ' || *hostname > 126)
+ *hostname = '^';
+ hostname++;
+ }
+ }
memcpy(oldest->chaddr, chaddr, 16);
oldest->yiaddr = yiaddr;
oldest->expires = time(NULL) + leasetime;
@@ -117,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t addr)
temp.s_addr = addr;
bb_info_msg("%s belongs to someone, reserving it for %u seconds",
inet_ntoa(temp), (unsigned)server_config.conflict_time);
- add_lease(blank_chaddr, addr, server_config.conflict_time);
+ add_lease(blank_chaddr, addr, server_config.conflict_time, NULL);
return 0;
}