summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/async/client.go19
-rw-r--r--dhcpv6/async/client_test.go8
-rw-r--r--dhcpv6/client6/client.go8
-rw-r--r--dhcpv6/nclient6/client_test.go16
-rw-r--r--dhcpv6/server6/server_test.go4
5 files changed, 41 insertions, 14 deletions
diff --git a/dhcpv6/async/client.go b/dhcpv6/async/client.go
index b2f977f..8a7fbff 100644
--- a/dhcpv6/async/client.go
+++ b/dhcpv6/async/client.go
@@ -3,6 +3,7 @@ package async
import (
"context"
"fmt"
+ "log"
"net"
"sync"
"time"
@@ -143,14 +144,20 @@ func (c *Client) send(packet dhcpv6.DHCPv6) {
raddr, err := c.remoteAddr()
if err != nil {
- p.Reject(err)
+ _ = p.Reject(err)
+ log.Printf("Warning: cannot get remote address :%v", err)
return
}
- c.connection.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
+ if err := c.connection.SetWriteDeadline(time.Now().Add(c.WriteTimeout)); err != nil {
+ _ = p.Reject(err)
+ log.Printf("Warning: cannot set write deadline :%v", err)
+ return
+ }
_, err = c.connection.WriteTo(packet.ToBytes(), raddr)
if err != nil {
- p.Reject(err)
+ _ = p.Reject(err)
+ log.Printf("Warning: cannot write to %s :%v", raddr, err)
return
}
@@ -163,7 +170,9 @@ func (c *Client) receive(_ dhcpv6.DHCPv6) {
received dhcpv6.DHCPv6
)
- c.connection.SetReadDeadline(time.Now().Add(c.ReadTimeout))
+ if err := c.connection.SetReadDeadline(time.Now().Add(c.ReadTimeout)); err != nil {
+ log.Printf("Warning: cannot set read deadline :%v", err)
+ }
for {
buffer := make([]byte, client6.MaxUDPReceivedPacketSize)
n, _, _, _, err := c.connection.ReadMsgUDP(buffer, oobdata)
@@ -190,7 +199,7 @@ func (c *Client) receive(_ dhcpv6.DHCPv6) {
c.packetsLock.Lock()
if p, ok := c.packets[transactionID]; ok {
delete(c.packets, transactionID)
- p.Resolve(received)
+ _ = p.Resolve(received)
}
c.packetsLock.Unlock()
}
diff --git a/dhcpv6/async/client_test.go b/dhcpv6/async/client_test.go
index 8603248..14b8026 100644
--- a/dhcpv6/async/client_test.go
+++ b/dhcpv6/async/client_test.go
@@ -37,7 +37,9 @@ func serve(ctx context.Context, addr *net.UDPAddr, response dhcpv6.DHCPv6) error
case <-ctx.Done():
return
default:
- conn.SetReadDeadline(time.Now().Add(1 * time.Second))
+ if err := conn.SetReadDeadline(time.Now().Add(1 * time.Second)); err != nil {
+ panic(err)
+ }
n, _, _, src, err := conn.ReadMsgUDP(buffer, oobdata)
if err != nil {
continue
@@ -46,7 +48,9 @@ func serve(ctx context.Context, addr *net.UDPAddr, response dhcpv6.DHCPv6) error
if err != nil {
continue
}
- conn.SetWriteDeadline(time.Now().Add(1 * time.Second))
+ if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); err != nil {
+ panic(err)
+ }
_, err = conn.WriteTo(response.ToBytes(), src)
if err != nil {
continue
diff --git a/dhcpv6/client6/client.go b/dhcpv6/client6/client.go
index 3722579..091a58b 100644
--- a/dhcpv6/client6/client.go
+++ b/dhcpv6/client6/client.go
@@ -141,7 +141,9 @@ func (c *Client) sendReceive(ifname string, packet dhcpv6.DHCPv6, expectedType d
}
// send the packet out
- conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
+ if err := conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout)); err != nil {
+ return nil, err
+ }
_, err = conn.WriteTo(packet.ToBytes(), &raddr)
if err != nil {
return nil, err
@@ -149,7 +151,9 @@ func (c *Client) sendReceive(ifname string, packet dhcpv6.DHCPv6, expectedType d
// wait for a reply
oobdata := []byte{} // ignoring oob data
- conn.SetReadDeadline(time.Now().Add(c.ReadTimeout))
+ if err := conn.SetReadDeadline(time.Now().Add(c.ReadTimeout)); err != nil {
+ return nil, err
+ }
var (
adv dhcpv6.DHCPv6
isMessage bool
diff --git a/dhcpv6/nclient6/client_test.go b/dhcpv6/nclient6/client_test.go
index b48f1f1..8d55faf 100644
--- a/dhcpv6/nclient6/client_test.go
+++ b/dhcpv6/nclient6/client_test.go
@@ -18,6 +18,7 @@ import (
"github.com/hugelgupf/socketpair"
"github.com/insomniacslk/dhcp/dhcpv6"
"github.com/insomniacslk/dhcp/dhcpv6/server6"
+ "github.com/stretchr/testify/require"
)
type handler struct {
@@ -41,7 +42,9 @@ func (h *handler) handle(conn net.PacketConn, peer net.Addr, msg dhcpv6.DHCPv6)
resps := h.responses[0]
// What should we send in response?
for _, resp := range resps {
- conn.WriteTo(resp.ToBytes(), peer)
+ if _, err := conn.WriteTo(resp.ToBytes(), peer); err != nil {
+ panic(err)
+ }
}
h.responses = h.responses[1:]
}
@@ -69,7 +72,11 @@ func serveAndClient(ctx context.Context, responses [][]*dhcpv6.Message, opt ...C
if err != nil {
panic(err)
}
- go s.Serve()
+ go func() {
+ if err := s.Serve(); err != nil {
+ panic(err)
+ }
+ }()
return mc, serverRawConn
}
@@ -81,7 +88,7 @@ func ComparePacket(got *dhcpv6.Message, want *dhcpv6.Message) error {
if (want == nil || got == nil) && (got != want) {
return fmt.Errorf("packet got %v, want %v", got, want)
}
- if bytes.Compare(got.ToBytes(), want.ToBytes()) != 0 {
+ if !bytes.Equal(got.ToBytes(), want.ToBytes()) {
return fmt.Errorf("packet got %v, want %v", got, want)
}
return nil
@@ -204,7 +211,8 @@ func TestSimpleSendAndReadDiscardGarbage(t *testing.T) {
defer mc.Close()
// Too short for valid DHCPv4 packet.
- udpConn.WriteTo([]byte{0x01}, nil)
+ _, err := udpConn.WriteTo([]byte{0x01}, nil)
+ require.NoError(t, err)
rcvd, err := mc.SendAndRead(context.Background(), AllDHCPServers, pkt, nil)
if err != nil {
diff --git a/dhcpv6/server6/server_test.go b/dhcpv6/server6/server_test.go
index c81525a..cf5fbea 100644
--- a/dhcpv6/server6/server_test.go
+++ b/dhcpv6/server6/server_test.go
@@ -37,7 +37,9 @@ func setUpClientAndServer(handler Handler) (*nclient6.Client, *Server) {
if err != nil {
panic(err)
}
- go s.Serve()
+ go func() {
+ _ = s.Serve()
+ }()
clientConn, err := net.DialUDP("udp6", &net.UDPAddr{IP: net.ParseIP("::1")}, s.conn.LocalAddr().(*net.UDPAddr))
if err != nil {