Change dhcp plugin to send ClientID allowing container to have multiple CNI
interfaces using dhcp ipam. Vendor latest dhcp4server, dhcp4client, dhcp4 Added additional tests for new functionality in dhcp2_test.go Wrap d2g dhcp4client calls with our own which add clientID to packet.
This commit is contained in:
17
vendor/github.com/d2g/dhcp4server/leasepool/memorypool/memorypool.go
generated
vendored
17
vendor/github.com/d2g/dhcp4server/leasepool/memorypool/memorypool.go
generated
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user