/* Add a lease into the table, clearing out any old ones */ struct dyn_lease* FAST_FUNC add_lease( const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime, const char *hostname, int hostname_len) { struct dyn_lease *oldest; /* clean out any old ones */ clear_lease(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { oldest->hostname[0] = '\0'; if (hostname) { char *p; if (hostname_len > sizeof(oldest->hostname)) hostname_len = sizeof(oldest->hostname); p = safe_strncpy(oldest->hostname, hostname, hostname_len); /* sanitization (s/non-ASCII/^/g) */ while (*p) { if (*p < ' ' || *p > 126) *p = '^'; p++; } } memcpy(oldest->lease_mac, chaddr, 6); oldest->lease_nip = yiaddr; oldest->expires = time(NULL) + leasetime; } return oldest; }
/* add a lease into the table, clearing out any old ones */ struct dhcpOfferedAddr *add_lease(u_int8_t *chaddr, u_int32_t yiaddr, unsigned long lease) #endif { struct dhcpOfferedAddr *oldest; #if 1 /* statitc lease --> Kide 2005/03/20 */ if ( (oldest = find_lease_by_yiaddr(yiaddr)) && oldest->is_static) goto STATIC_LEASE; // <-- #endif /* clean out any old ones */ clear_lease(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { #ifdef CONFIG_NK_DHCP_CLIENT_USER /* if lease is zero, mean it's static --> Kide 2005/03/20 */ oldest->is_static = (lease == 0) ? 1 : 0; lease = (lease == 0) ? server_config.lease : lease; #endif STATIC_LEASE: // <-- if(!(oldest->is_static)) { memcpy(oldest->chaddr, chaddr, 16); oldest->yiaddr = yiaddr; oldest->expires = get_time(0) + lease; } else { oldest->expires = get_time(0) + lease; } /* 2007/07/30 jane: bug fix dhcp status do not show client's host name */ #if 1 if (hostname) { memset(oldest->hostname, '\0', sizeof(oldest->hostname)); strcpy(oldest->hostname, hostname); } #endif if (packetType) //0:read ip, 2:Offer, 4:Ack oldest->packetType=(int)packetType; } return oldest; }
/* add a lease into the table, clearing out any old ones */ struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease) { struct dhcpOfferedAddr *oldest; /* clean out any old ones */ clear_lease(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { memcpy(oldest->chaddr, chaddr, 16); oldest->yiaddr = yiaddr; oldest->expires = time(0) + lease; } return oldest; }
/* Add a lease into the table, clearing out any old ones. * If chaddr == NULL, this is a conflict lease. */ struct dyn_lease* FAST_FUNC add_lease( const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime, const char *hostname, int hostname_len) { struct dyn_lease *oldest; /* clean out any old ones */ clear_leases(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { memset(oldest, 0, sizeof(*oldest)); if (hostname) { char *p; hostname_len++; /* include NUL */ if (hostname_len > sizeof(oldest->hostname)) hostname_len = sizeof(oldest->hostname); p = safe_strncpy(oldest->hostname, hostname, hostname_len); /* * Sanitization (s/bad_char/./g). * The intent is not to allow only "DNS-valid" hostnames, * but merely make dumpleases output safe for shells to use. * We accept "0-9A-Za-z._-", all other chars turn to dots. */ while (*p) { if (!isalnum(*p) && *p != '-' && *p != '_') *p = '.'; p++; } } if (chaddr) memcpy(oldest->lease_mac, chaddr, 6); oldest->lease_nip = yiaddr; oldest->expires = time(NULL) + leasetime; } return oldest; }
/* add a lease into the table, clearing out any old ones */ struct dhcpOfferedAddr *add_lease(uint8_t *hostname, const uint8_t *chaddr, uint32_t yiaddr, unsigned long lease) { struct dhcpOfferedAddr *oldest; /* clean out any old ones */ clear_lease(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { if (hostname) { uint8_t length = *(hostname-1); if (length>15) length = 15; memcpy(oldest->hostname, hostname, length); oldest->hostname[length] = 0; } memcpy(oldest->chaddr, chaddr, 16); oldest->yiaddr = yiaddr; oldest->expires = time(0) + lease; } return oldest; }
struct dhcpOfferedAddr *add_lease_fromfile(u_int8_t *chaddr, u_int32_t yiaddr, unsigned long lease, char *hostname) { struct dhcpOfferedAddr *oldest; /* clean out any old ones */ clear_lease(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { memcpy(oldest->chaddr, chaddr, 16); oldest->yiaddr = yiaddr; oldest->expires = time(0) + lease; if(hostname[0] != '\0') sprintf(oldest->hostname, "%s", hostname); } #ifdef GUEST_ZONE if (server_config.guestmac_check) { if (is_guest_mac(server_config.interface, chaddr)) { struct guest_mac_entry *newguest; if (!is_guest_exist(chaddr, &newguest)) { if (newguest) { memcpy(newguest->addr, chaddr, 6); newguest->valid = 1; } } } else { struct guest_mac_entry *guest = is_guest_exist(chaddr, NULL); if (guest) guest->valid = 0; } } #endif return oldest; }
/* Add a lease into the table, clearing out any old ones. * If chaddr == NULL, this is a conflict lease. */ struct dyn_lease* ICACHE_FLASH_ATTR add_lease( const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime, const char *hostname, int hostname_len) { struct dyn_lease *oldest; /* clean out any old ones */ clear_leases(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { memset(oldest, 0, sizeof(*oldest)); if (hostname) { char *p; hostname_len++; /* include NUL */ if (hostname_len > sizeof(oldest->hostname)) hostname_len = sizeof(oldest->hostname); p = (char *)strncpy(oldest->hostname, hostname, hostname_len); /* sanitization (s/non-ASCII/^/g) */ while (*p) { if (*p < ' ' || *p > 126) *p = '^'; p++; } } if (chaddr) memcpy(oldest->lease_mac, chaddr, 6); oldest->lease_nip = yiaddr; oldest->expires = time(NULL) + leasetime; } return oldest; }