Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/udhcp/leases.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/udhcp/leases.c
r3232 r3621 18 18 * and therefore can't ever match */ 19 19 for (i = 0; i < server_config.max_leases; i++) { 20 if (g_leases[i].expires < oldest_time) { 20 if (g_leases[i].expires == 0 /* empty entry */ 21 || g_leases[i].expires < oldest_time 22 ) { 21 23 oldest_time = g_leases[i].expires; 22 24 oldest_lease = &g_leases[i]; … … 66 68 hostname_len = sizeof(oldest->hostname); 67 69 p = safe_strncpy(oldest->hostname, hostname, hostname_len); 68 /* sanitization (s/non-ASCII/^/g) */ 70 /* 71 * Sanitization (s/bad_char/./g). 72 * The intent is not to allow only "DNS-valid" hostnames, 73 * but merely make dumpleases output safe for shells to use. 74 * We accept "0-9A-Za-z._-", all other chars turn to dots. 75 */ 69 76 while (*p) { 70 if ( *p < ' ' || *p > 126)71 *p = ' ^';77 if (!isalnum(*p) && *p != '-' && *p != '_') 78 *p = '.'; 72 79 p++; 73 80 } … … 113 120 114 121 /* Check if the IP is taken; if it is, add it to the lease table */ 115 static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac )122 static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigned arpping_ms) 116 123 { 117 124 struct in_addr temp; … … 121 128 server_config.server_nip, 122 129 server_config.server_mac, 123 server_config.interface); 130 server_config.interface, 131 arpping_ms); 124 132 if (r) 125 133 return r; 126 134 127 135 temp.s_addr = nip; 128 bb_ info_msg("%s belongs to someone, reserving it for %u seconds",136 bb_error_msg("%s belongs to someone, reserving it for %u seconds", 129 137 inet_ntoa(temp), (unsigned)server_config.conflict_time); 130 138 add_lease(NULL, nip, server_config.conflict_time, NULL, 0); … … 133 141 134 142 /* Find a new usable (we think) address */ 135 uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac )143 uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arpping_ms) 136 144 { 137 145 uint32_t addr; … … 178 186 if (!lease) { 179 187 //TODO: DHCP servers do not always sit on the same subnet as clients: should *ping*, not arp-ping! 180 if (nobody_responds_to_arp(nip, safe_mac ))188 if (nobody_responds_to_arp(nip, safe_mac, arpping_ms)) 181 189 return nip; 182 190 } else { … … 195 203 if (oldest_lease 196 204 && is_expired_lease(oldest_lease) 197 && nobody_responds_to_arp(oldest_lease->lease_nip, safe_mac )205 && nobody_responds_to_arp(oldest_lease->lease_nip, safe_mac, arpping_ms) 198 206 ) { 199 207 return oldest_lease->lease_nip;
Note:
See TracChangeset
for help on using the changeset viewer.