From 51abf90db663e48683edef677111191a5a9d8747 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Fri, 2 Sep 2022 09:16:19 +0200 Subject: [PATCH] Use net/netip in derp server --- app_test.go | 6 +++--- derp_server.go | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app_test.go b/app_test.go index d8fd14fc..c2ebe4ad 100644 --- a/app_test.go +++ b/app_test.go @@ -1,11 +1,11 @@ package headscale import ( + "net/netip" "os" "testing" "gopkg.in/check.v1" - "inet.af/netaddr" ) func Test(t *testing.T) { @@ -39,8 +39,8 @@ func (s *Suite) ResetDB(c *check.C) { c.Fatal(err) } cfg := Config{ - IPPrefixes: []netaddr.IPPrefix{ - netaddr.MustParseIPPrefix("10.27.0.0/23"), + IPPrefixes: []netip.Prefix{ + netip.MustParsePrefix("10.27.0.0/23"), }, } diff --git a/derp_server.go b/derp_server.go index 098ca53e..dbdbc7a5 100644 --- a/derp_server.go +++ b/derp_server.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "net/http" + "net/netip" "net/url" "strconv" "strings" @@ -163,7 +164,7 @@ func (h *Headscale) DERPHandler( pubKeyStr) } - h.DERPServer.tailscaleDERP.Accept(netConn, conn, netConn.RemoteAddr().String()) + h.DERPServer.tailscaleDERP.Accept(req.Context(), netConn, conn, netConn.RemoteAddr().String()) } // DERPProbeHandler is the endpoint that js/wasm clients hit to measure @@ -276,7 +277,8 @@ func serverSTUNListener(ctx context.Context, packetConn *net.UDPConn) { continue } - res := stun.Response(txid, udpAddr.IP, uint16(udpAddr.Port)) + addr, _ := netip.AddrFromSlice(udpAddr.IP) + res := stun.Response(txid, netip.AddrPortFrom(addr, uint16(udpAddr.Port))) _, err = packetConn.WriteTo(res, udpAddr) if err != nil { log.Trace().Caller().Err(err).Msgf("Issue writing to UDP")