mdlayher / ndp

Package ndp implements the Neighbor Discovery Protocol, as described in RFC 4861. MIT Licensed.

Home Page:https://tools.ietf.org/html/rfc4861

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The default ControlMessage set on WriteTo causes failures when the connection is bound to link-local on macOS

mcphailtom opened this issue · comments

I've come across an issue that seems to be specific to macOS when binding an ndp connection to the LinkLocal address of an interface. Subsequent Writes using WriteTo will fail with a sendmsg: no route to host error. This problem does not occur when binding the connection to either the Global scoped address or Unspecified.

After some digging and reconstructing the process manually I managed to narrow the issue down to the WriteTo providing a default ControlMessage to the ipv6.PacketConn when nil is passed to the WriteTo method. Specifically it seems that explicitly setting the Src field of the ControlMessage is what causes this to fail. Passing nil or using a ControlMessage without the Src field set avoids the problem

None of this is reproducible on Linux where all versions worked as expected.