dhcp module update

This commit is contained in:
Nathan Gieseker
2019-06-26 01:25:22 -07:00
parent addbcd34b4
commit ce60e8eb3d
9 changed files with 123 additions and 52 deletions

View File

@ -81,13 +81,23 @@ func (t *MemoryPool) GetLease(leaseIP net.IP) (bool, leasepool.Lease, error) {
return false, leasepool.Lease{}, nil
}
//Get the lease already in use by that hardware address.
func (t *MemoryPool) GetLeaseForHardwareAddress(macAddress net.HardwareAddr) (bool, leasepool.Lease, error) {
func makeKey(macAddress net.HardwareAddr, clientID []byte) []byte {
key := []byte(macAddress)
if len(clientID) > 0 {
key = append(key, clientID...)
}
return key
}
//Get the lease already in use by that hardware address and/or client identifier.
func (t *MemoryPool) GetLeaseForClient(macAddress net.HardwareAddr, clientID []byte) (bool, leasepool.Lease, error) {
t.poolLock.Lock()
defer t.poolLock.Unlock()
needleKey := makeKey(macAddress, clientID)
for i := range t.pool {
if bytes.Equal(t.pool[i].MACAddress, macAddress) {
haystackKey := makeKey(t.pool[i].MACAddress, t.pool[i].ClientID)
if bytes.Equal(needleKey, haystackKey) {
return true, t.pool[i], nil
}
}
@ -139,6 +149,7 @@ func (t *MemoryPool) UpdateLease(lease leasepool.Lease) (bool, error) {
if t.pool[i].IP.Equal(lease.IP) {
t.pool[i].MACAddress = lease.MACAddress
t.pool[i].ClientID = lease.ClientID
t.pool[i].Hostname = lease.Hostname
t.pool[i].Expiry = lease.Expiry
t.pool[i].Status = lease.Status