dhcpd: support static ip address for mac

This commit is contained in:
nadoo committed 2021-06-10 20:09:21 +08:00
1 parent 41fee381d0
commit d92e7f6191
6 files changed
+48 -11

No files matched your search

+13
View File
@@ -87,6 +87,19 @@ func (p *Pool) LeaseIP(mac net.HardwareAddr) (net.IP, error) {
return nil, errors.New("no more ip can be leased")
}
// LeaseStaticIP leases static ip from pool according to the given mac.
func (p *Pool) LeaseStaticIP(mac net.HardwareAddr, ip net.IP) {
p.mutex.Lock()
defer p.mutex.Unlock()
for _, item := range p.items {
if item.ip.Equal(ip) {
item.mac = mac
item.expire = time.Now().Add(time.Hour * 24 * 365 * 50) // 50 years
}
}
}
// ReleaseIP releases ip from pool according to the given mac.
func (p *Pool) ReleaseIP(mac net.HardwareAddr) {
p.mutex.Lock()