diff options
author | 2022-02-02 13:38:49 -0600 | |
---|---|---|
committer | 2022-02-02 13:38:49 -0600 | |
commit | 90300178a6c24d4dad3c49f8ce636aeafbddfa2a (patch) | |
tree | 1870ddb7515e886d893567bd7c4f1c0ce741d94e /tun/netstack/tun.go | |
parent | fix addressing and deadlines (diff) | |
download | wireguard-go-tp/icmp-fixes.tar.xz wireguard-go-tp/icmp-fixes.zip |
Handle whole ICMP headerstp/icmp-fixes
Theoretically, this change would allow us to send ICMP replies from
these sockets. In practice, netstack filters anything but EchoRequest,
so this change mostly just adds annoyance right now. But in the
future, netstack might fix this, and this API would then work for
more than one use case.
Signed-off-by: Thomas Ptacek <thomas@sockpuppet.org>
Diffstat (limited to 'tun/netstack/tun.go')
-rw-r--r-- | tun/netstack/tun.go | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go index 058aca5..9d4b467 100644 --- a/tun/netstack/tun.go +++ b/tun/netstack/tun.go @@ -398,19 +398,7 @@ func (pc *PingConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { return 0, fmt.Errorf("ping write: mismatched protocols") } - var buf buffer.View - if ia.addr.Is4() { - buf = buffer.NewView(header.ICMPv4MinimumSize + len(p)) - copy(buf[header.ICMPv4MinimumSize:], p) - icmp := header.ICMPv4(buf) - icmp.SetType(header.ICMPv4Echo) - } else if ia.addr.Is6() { - buf = buffer.NewView(header.ICMPv6MinimumSize + len(p)) - copy(buf[header.ICMPv6MinimumSize:], p) - icmp := header.ICMPv6(buf) - icmp.SetType(header.ICMPv6EchoRequest) - } - + buf := buffer.NewViewFromBytes(p) rdr := buf.Reader() rfa, _ := convertToFullAddr(netip.AddrPortFrom(ia.addr, 0)) // won't block, no deadlines @@ -462,12 +450,7 @@ func (pc *PingConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) { } } - min := header.ICMPv6MinimumSize - if pc.laddr.addr.Is4() { - min = header.ICMPv4MinimumSize - } - reply := make([]byte, min+len(p)) - w := tcpip.SliceWriter(reply) + w := tcpip.SliceWriter(p) res, tcpipErr := pc.ep.Read(&w, tcpip.ReadOptions{ NeedRemoteAddr: true, @@ -477,8 +460,7 @@ func (pc *PingConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) { } addr = PingAddr{netip.AddrFromSlice([]byte(res.RemoteAddr.Addr))} - copy(p, reply[min:res.Count]) - return res.Count - min, addr, nil + return res.Count, addr, nil } func (pc *PingConn) Read(p []byte) (n int, err error) { |