wgengine/magicsock, types/nettype, etc: finish ReadFromUDPAddrPort netip migration

So we're staying within the netip.Addr/AddrPort consistently and
avoiding allocs/conversions to the legacy net addr types.

Updates #5162

Change-Id: I59feba60d3de39f773e68292d759766bac98c917
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-04-15 13:08:16 -07:00
committed by Brad Fitzpatrick
parent 29f7df9d8f
commit 10f1c90f4d
8 changed files with 48 additions and 54 deletions

View File

@@ -824,13 +824,21 @@ func (c *conn) Write(buf []byte) (int, error) {
}
func (c *conn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
n, ap, err := c.ReadFromUDPAddrPort(p)
if err != nil {
return 0, nil, err
}
return n, net.UDPAddrFromAddrPort(ap), nil
}
func (c *conn) ReadFromUDPAddrPort(p []byte) (n int, addr netip.AddrPort, err error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ar := &activeRead{cancel: cancel}
if err := c.canRead(); err != nil {
return 0, nil, err
return 0, netip.AddrPort{}, err
}
c.registerActiveRead(ar, true)
@@ -840,14 +848,9 @@ func (c *conn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
case pkt := <-c.in:
n = copy(p, pkt.Payload)
pkt.Trace("PacketConn.ReadFrom")
ua := &net.UDPAddr{
IP: pkt.Src.Addr().AsSlice(),
Port: int(pkt.Src.Port()),
Zone: pkt.Src.Addr().Zone(),
}
return n, ua, nil
return n, pkt.Src, nil
case <-ctx.Done():
return 0, nil, context.DeadlineExceeded
return 0, netip.AddrPort{}, context.DeadlineExceeded
}
}