From 9b8ca219a1f4a5863c35de766e2c367299bfd768 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 1 Jul 2020 10:17:08 -0700 Subject: [PATCH] wgengine/magicsock: remove allocs in UDP write, use new netaddr.PutUDPAddr The allocs were only introduced yesterday with a TODO. Now they're gone again. --- go.mod | 2 +- go.sum | 2 ++ wgengine/magicsock/magicsock.go | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1f85c8ad8..2227aa42c 100644 --- a/go.mod +++ b/go.mod @@ -29,6 +29,6 @@ require ( golang.org/x/sys v0.0.0-20200501052902-10377860bb8e golang.org/x/time v0.0.0-20191024005414-555d28b269f0 honnef.co/go/tools v0.0.1-2020.1.4 // indirect - inet.af/netaddr v0.0.0-20200629220211-f44a6d25c536 + inet.af/netaddr v0.0.0-20200701171350-6509743f79d9 rsc.io/goversion v1.2.0 ) diff --git a/go.sum b/go.sum index 3b98b35f8..d01a0c902 100644 --- a/go.sum +++ b/go.sum @@ -162,5 +162,7 @@ inet.af/netaddr v0.0.0-20200513162223-787f13e36cbe h1:WjJ6wZhXEWQA3FFSwOjG8tO2q1 inet.af/netaddr v0.0.0-20200513162223-787f13e36cbe/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww= inet.af/netaddr v0.0.0-20200629220211-f44a6d25c536 h1:XFVw2MVOtmHBidx70M+I6vIw2F6f55UyXvkiKfIrE38= inet.af/netaddr v0.0.0-20200629220211-f44a6d25c536/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww= +inet.af/netaddr v0.0.0-20200701171350-6509743f79d9 h1:F41nQsn8UGDPDXsOPwZQiaK8BmItPzyb0PYgjJSYIzw= +inet.af/netaddr v0.0.0-20200701171350-6509743f79d9/go.mod h1:qqYzz/2whtrbWJvt+DNWQyvekNN4ePQZcg2xc2/Yjww= rsc.io/goversion v1.2.0 h1:SPn+NLTiAG7w30IRK/DKp1BjvpWabYgxlLp/+kx5J8w= rsc.io/goversion v1.2.0/go.mod h1:Eih9y/uIBS3ulggl7KNJ09xGSLcuNaLgmvvqa07sgfo= diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 68a5612e8..c24610076 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -805,8 +805,9 @@ func (c *Conn) Send(b []byte, ep conn.Endpoint) error { // sendUDP sends UDP packet b to ipp. func (c *Conn) sendUDP(ipp netaddr.IPPort, b []byte) error { - addr := ipp.UDPAddr() // TOOD(bradfitz): add alloc-free netaddr.WriteTo helper - return c.sendUDPStd(addr, b) + ua := ipp.UDPAddr() + defer netaddr.PutUDPAddr(ua) + return c.sendUDPStd(ua, b) } func (c *Conn) sendUDPStd(addr *net.UDPAddr, b []byte) (err error) {