aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/leases.c
diff options
context:
space:
mode:
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 3044c2040..d62f32471 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)
48 48
49 49
50/* Add a lease into the table, clearing out any old ones */ 50/* Add a lease into the table, clearing out any old ones */
51struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime) 51struct dhcpOfferedAddr* FAST_FUNC add_lease(
52 const uint8_t *chaddr, uint32_t yiaddr,
53 leasetime_t leasetime, uint8_t *hostname)
52{ 54{
53 struct dhcpOfferedAddr *oldest; 55 struct dhcpOfferedAddr *oldest;
56 uint8_t hostname_length;
54 57
55 /* clean out any old ones */ 58 /* clean out any old ones */
56 clear_lease(chaddr, yiaddr); 59 clear_lease(chaddr, yiaddr);
@@ -58,6 +61,19 @@ struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiad
58 oldest = oldest_expired_lease(); 61 oldest = oldest_expired_lease();
59 62
60 if (oldest) { 63 if (oldest) {
64 oldest->hostname[0] = '\0';
65 if (hostname) {
66 hostname_length = hostname[-1]; /* look at option size byte */
67 if (hostname_length > sizeof(oldest->hostname))
68 hostname_length = sizeof(oldest->hostname);
69 hostname = (uint8_t*) safe_strncpy((char*)oldest->hostname, (char*)hostname, hostname_length);
70 /* sanitization (s/non-ACSII/^/g) */
71 while (*hostname) {
72 if (*hostname < ' ' || *hostname > 126)
73 *hostname = '^';
74 hostname++;
75 }
76 }
61 memcpy(oldest->chaddr, chaddr, 16); 77 memcpy(oldest->chaddr, chaddr, 16);
62 oldest->yiaddr = yiaddr; 78 oldest->yiaddr = yiaddr;
63 oldest->expires = time(NULL) + leasetime; 79 oldest->expires = time(NULL) + leasetime;
@@ -117,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t addr)
117 temp.s_addr = addr; 133 temp.s_addr = addr;
118 bb_info_msg("%s belongs to someone, reserving it for %u seconds", 134 bb_info_msg("%s belongs to someone, reserving it for %u seconds",
119 inet_ntoa(temp), (unsigned)server_config.conflict_time); 135 inet_ntoa(temp), (unsigned)server_config.conflict_time);
120 add_lease(blank_chaddr, addr, server_config.conflict_time); 136 add_lease(blank_chaddr, addr, server_config.conflict_time, NULL);
121 return 0; 137 return 0;
122} 138}
123 139