1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

Use net/netip in derp server

This commit is contained in:
Juan Font Alonso 2022-09-02 09:16:19 +02:00
parent 71410cb6da
commit 51abf90db6
2 changed files with 7 additions and 5 deletions

View File

@ -1,11 +1,11 @@
package headscale package headscale
import ( import (
"net/netip"
"os" "os"
"testing" "testing"
"gopkg.in/check.v1" "gopkg.in/check.v1"
"inet.af/netaddr"
) )
func Test(t *testing.T) { func Test(t *testing.T) {
@ -39,8 +39,8 @@ func (s *Suite) ResetDB(c *check.C) {
c.Fatal(err) c.Fatal(err)
} }
cfg := Config{ cfg := Config{
IPPrefixes: []netaddr.IPPrefix{ IPPrefixes: []netip.Prefix{
netaddr.MustParseIPPrefix("10.27.0.0/23"), netip.MustParsePrefix("10.27.0.0/23"),
}, },
} }

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"net/netip"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
@ -163,7 +164,7 @@ func (h *Headscale) DERPHandler(
pubKeyStr) 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 // DERPProbeHandler is the endpoint that js/wasm clients hit to measure
@ -276,7 +277,8 @@ func serverSTUNListener(ctx context.Context, packetConn *net.UDPConn) {
continue 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) _, err = packetConn.WriteTo(res, udpAddr)
if err != nil { if err != nil {
log.Trace().Caller().Err(err).Msgf("Issue writing to UDP") log.Trace().Caller().Err(err).Msgf("Issue writing to UDP")