diff options
Diffstat (limited to 'dhcpv6')
-rw-r--r-- | dhcpv6/nclient6/client.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/dhcpv6/nclient6/client.go b/dhcpv6/nclient6/client.go index 74cdf5c..c40e6c8 100644 --- a/dhcpv6/nclient6/client.go +++ b/dhcpv6/nclient6/client.go @@ -71,6 +71,9 @@ type Client struct { // wg protects the receiveLoop. wg sync.WaitGroup + // printDropped logs dropped packets to logger if true. + printDropped bool + pendingMu sync.Mutex // pending stores the distribution channels for each pending // TransactionID. receiveLoop uses this map to determine which channel @@ -217,6 +220,12 @@ func (c *Client) receiveLoop() { msg, err := dhcpv6.MessageFromBytes(b[:n]) if err != nil { // Not a valid DHCP packet; keep listening. + if c.printDropped { + if len(b) > 12 { + b = b[:12] + } + c.logger.Printf("Invalid DHCPv6 message received (len %d bytes), first 12 bytes: %#x", n, b) + } continue } @@ -231,6 +240,9 @@ func (c *Client) receiveLoop() { // This send may block. case p.ch <- msg: } + } else if c.printDropped { + // The Stringer will print the transaction ID. + c.logger.Printf("No client waiting for msg with this XID: %s", msg) } c.pendingMu.Unlock() } @@ -249,6 +261,13 @@ func WithTimeout(d time.Duration) ClientOpt { } } +// WithLogDroppedPackets logs a short message for dropped packets. +func WithLogDroppedPackets() ClientOpt { + return func(c *Client) { + c.printDropped = true + } +} + // WithRetry configures the number of retransmissions to attempt. // // Default is 3. |