diff options
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/nclient4/lease.go | 2 | ||||
-rw-r--r-- | dhcpv4/nclient4/lease_test.go | 16 |
2 files changed, 14 insertions, 4 deletions
diff --git a/dhcpv4/nclient4/lease.go b/dhcpv4/nclient4/lease.go index 1bd77e5..838e39b 100644 --- a/dhcpv4/nclient4/lease.go +++ b/dhcpv4/nclient4/lease.go @@ -50,7 +50,7 @@ func (c *Client) Release(lease *Lease) error { } //This is to make sure use same client identification options used during //DORA, so that DHCP server could identify the required lease - for t, _ := range lease.IDOptions { + for t := range lease.IDOptions { req.UpdateOption( dhcpv4.OptGeneric(dhcpv4.GenericOptionCode(t), lease.IDOptions.Get(dhcpv4.GenericOptionCode(t))), diff --git a/dhcpv4/nclient4/lease_test.go b/dhcpv4/nclient4/lease_test.go index 22d97e0..96dfae0 100644 --- a/dhcpv4/nclient4/lease_test.go +++ b/dhcpv4/nclient4/lease_test.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "net" + "sync" "testing" "time" @@ -41,14 +42,16 @@ type testServerLease struct { } type testServerLeaseList struct { - list []*testServerLease - clientIDOptions dhcpv4.OptionCodeList - lastTestSvrErr error + list []*testServerLease + clientIDOptions dhcpv4.OptionCodeList + lastTestSvrErr error + lastTestSvrErrLock *sync.RWMutex } func newtestServerLeaseList(l dhcpv4.OptionCodeList) *testServerLeaseList { r := &testServerLeaseList{} r.clientIDOptions = l + r.lastTestSvrErrLock = &sync.RWMutex{} return r } @@ -184,6 +187,8 @@ func (sll *testServerLeaseList) handle(conn net.PacketConn, peer net.Addr, m *dh if m.OpCode != dhcpv4.OpcodeBootRequest { log.Fatal("Not a BootRequest!") } + sll.lastTestSvrErrLock.Lock() + defer sll.lastTestSvrErrLock.Unlock() switch m.MessageType() { case dhcpv4.MessageTypeDiscover, dhcpv4.MessageTypeRequest: sll.lastTestSvrErr = sll.testLeaseDORAHandle(conn, peer, m) @@ -243,13 +248,18 @@ func (sll *testServerLeaseList) runTest(t *testing.T) { } lease, err := clnt.Request(context.Background(), modList...) + sll.lastTestSvrErrLock.RLock() keepgoing := chkerr(err, sll.lastTestSvrErr, l.ShouldFail, t) + sll.lastTestSvrErrLock.RUnlock() if keepgoing { err = clnt.Release(lease) //this sleep is to make sure release is handled by server time.Sleep(time.Second) + sll.lastTestSvrErrLock.RLock() chkerr(err, sll.lastTestSvrErr, l.ShouldFail, t) + sll.lastTestSvrErrLock.RUnlock() } + } } |