Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47af2b7

Browse files
committed
fix tailscale types
1 parent 4348b88 commit 47af2b7

18 files changed

+115
-124
lines changed

agent/agent.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"net"
12+
"net/netip"
1213
"net/url"
1314
"os"
1415
"os/exec"
@@ -27,7 +28,6 @@ import (
2728
"go.uber.org/atomic"
2829
gossh "golang.org/x/crypto/ssh"
2930
"golang.org/x/xerrors"
30-
"inet.af/netaddr"
3131
"tailscale.com/tailcfg"
3232

3333
"cdr.dev/slog"
@@ -62,7 +62,7 @@ type Options struct {
6262
}
6363

6464
type Metadata struct {
65-
IPAddresses []netaddr.IP `json:"ip_addresses"`
65+
IPAddresses []netip.Addr `json:"ip_addresses"`
6666
DERPMap *tailcfg.DERPMap `json:"derpmap"`
6767
EnvironmentVariables map[string]string `json:"environment_variables"`
6868
StartupScript string `json:"startup_script"`
@@ -174,10 +174,10 @@ func (a *agent) run(ctx context.Context) {
174174
}
175175
}
176176

177-
func (a *agent) runTailnet(ctx context.Context, addresses []netaddr.IP, derpMap *tailcfg.DERPMap) {
178-
ipRanges := make([]netaddr.IPPrefix, 0, len(addresses))
177+
func (a *agent) runTailnet(ctx context.Context, addresses []netip.Addr, derpMap *tailcfg.DERPMap) {
178+
ipRanges := make([]netip.Prefix, 0, len(addresses))
179179
for _, address := range addresses {
180-
ipRanges = append(ipRanges, netaddr.IPPrefixFrom(address, 128))
180+
ipRanges = append(ipRanges, netip.PrefixFrom(address, 128))
181181
}
182182
var err error
183183
a.network, err = tailnet.New(&tailnet.Options{

agent/conn.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"fmt"
77
"io"
88
"net"
9+
"net/netip"
910
"net/url"
1011
"strconv"
1112
"strings"
1213
"time"
1314

1415
"golang.org/x/crypto/ssh"
1516
"golang.org/x/xerrors"
16-
"inet.af/netaddr"
1717

1818
"github.com/coder/coder/peer"
1919
"github.com/coder/coder/peerbroker/proto"
@@ -135,7 +135,7 @@ func (c *WebRTCConn) Close() error {
135135
}
136136

137137
type TailnetConn struct {
138-
Target netaddr.IP
138+
Target netip.Addr
139139
*tailnet.Server
140140
}
141141

@@ -156,7 +156,7 @@ func (c *TailnetConn) ReconnectingPTY(id string, height, width uint16, command s
156156
}
157157

158158
func (c *TailnetConn) SSH() (net.Conn, error) {
159-
return c.DialContextTCP(context.Background(), netaddr.IPPortFrom(c.Target, 12212))
159+
return c.DialContextTCP(context.Background(), netip.AddrPortFrom(c.Target, 12212))
160160
}
161161

162162
// SSHClient calls SSH to create a client that uses a weak cipher
@@ -181,5 +181,5 @@ func (c *TailnetConn) SSHClient() (*ssh.Client, error) {
181181
func (c *TailnetConn) DialContext(ctx context.Context, network string, addr string) (net.Conn, error) {
182182
_, rawPort, _ := net.SplitHostPort(addr)
183183
port, _ := strconv.Atoi(rawPort)
184-
return c.Server.DialContextTCP(ctx, netaddr.IPPortFrom(c.Target, uint16(port)))
184+
return c.Server.DialContextTCP(ctx, netip.AddrPortFrom(c.Target, uint16(port)))
185185
}

cli/ssh.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ import (
1919
gosshagent "golang.org/x/crypto/ssh/agent"
2020
"golang.org/x/term"
2121
"golang.org/x/xerrors"
22+
tslogger "tailscale.com/types/logger"
2223

2324
"github.com/coder/coder/cli/cliflag"
2425
"github.com/coder/coder/cli/cliui"
2526
"github.com/coder/coder/coderd/autobuild/notify"
2627
"github.com/coder/coder/coderd/util/ptr"
2728
"github.com/coder/coder/codersdk"
2829
"github.com/coder/coder/cryptorand"
30+
"github.com/coder/coder/peer/peerwg"
2931
)
3032

3133
var workspacePollInterval = time.Minute
@@ -112,12 +114,12 @@ func ssh() *cobra.Command {
112114
newSSHClient = conn.SSHClient
113115
} else {
114116
// TODO: more granual control of Tailscale logging.
115-
// peerwg.Logf = tslogger.Discard
117+
peerwg.Logf = tslogger.Discard
116118

117119
// ipv6 := peerwg.UUIDToNetaddr(uuid.New())
118120
// wgn, err := peerwg.New(
119121
// slog.Make(sloghuman.Sink(os.Stderr)),
120-
// []netaddr.IPPrefix{netaddr.IPPrefixFrom(ipv6, 128)},
122+
// []netip.Prefix{netip.PrefixFrom(ipv6, 128)},
121123
// )
122124
// if err != nil {
123125
// return xerrors.Errorf("create wireguard network: %w", err)
@@ -136,18 +138,19 @@ func ssh() *cobra.Command {
136138
// err = wgn.AddPeer(peerwg.Handshake{
137139
// Recipient: workspaceAgent.ID,
138140
// DiscoPublicKey: workspaceAgent.DiscoPublicKey,
139-
// NodePublicKey: workspaceAgent.WireguardPublicKey,
140-
// IPv6: workspaceAgent.IPv6.IP(),
141+
// NodePublicKey: workspaceAgent.NodePublicKey,
142+
// IPv6: workspaceAgent.IPAddresses[0], // TODO: fix?
141143
// })
142144
// if err != nil {
143145
// return xerrors.Errorf("add workspace agent as peer: %w", err)
144146
// }
145147

146148
// if stdio {
147-
// rawSSH, err := wgn.SSH(cmd.Context(), workspaceAgent.IPv6.IP())
149+
// rawSSH, err := wgn.SSH(cmd.Context(), workspaceAgent.IPAddresses[0]) // TODO: fix?
148150
// if err != nil {
149151
// return err
150152
// }
153+
// defer rawSSH.Close()
151154

152155
// go func() {
153156
// _, _ = io.Copy(cmd.OutOrStdout(), rawSSH)
@@ -156,15 +159,14 @@ func ssh() *cobra.Command {
156159
// return nil
157160
// }
158161

159-
// sshClient, err = wgn.SSHClient(cmd.Context(), workspaceAgent.IPv6.IP())
160-
// if err != nil {
161-
// return err
162+
// newSSHClient = func() (*gossh.Client, error) {
163+
// return wgn.SSHClient(ctx, workspaceAgent.IPAddresses[0]) // TODO: fix?
162164
// }
165+
}
163166

164-
// sshSession, err = sshClient.NewSession()
165-
// if err != nil {
166-
// return err
167-
// }
167+
sshClient, err := newSSHClient()
168+
if err != nil {
169+
return err
168170
}
169171
defer sshClient.Close()
170172

cli/wireguardtunnel.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55
"fmt"
66
"net"
7+
"net/netip"
78
"strconv"
89
"sync"
910

1011
"github.com/pion/udp"
1112
"github.com/spf13/cobra"
1213
"golang.org/x/xerrors"
13-
"inet.af/netaddr"
1414

1515
coderagent "github.com/coder/coder/agent"
1616
"github.com/coder/coder/cli/cliui"
@@ -93,7 +93,7 @@ func wireguardPortForward() *cobra.Command {
9393
// ipv6 := peerwg.UUIDToNetaddr(uuid.New())
9494
// wgn, err := peerwg.New(
9595
// slog.Make(sloghuman.Sink(os.Stderr)),
96-
// []netaddr.IPPrefix{netaddr.IPPrefixFrom(ipv6, 128)},
96+
// []netip.Prefix{netip.PrefixFrom(ipv6, 128)},
9797
// )
9898
// if err != nil {
9999
// return xerrors.Errorf("create wireguard network: %w", err)
@@ -180,7 +180,7 @@ func listenAndPortForwardWireguard(ctx context.Context, cmd *cobra.Command,
180180
wgn *peerwg.Network,
181181
wg *sync.WaitGroup,
182182
spec portForwardSpec,
183-
agentIP netaddr.IP,
183+
agentIP netip.Addr,
184184
) (net.Listener, error) {
185185
_, _ = fmt.Fprintf(cmd.OutOrStderr(), "Forwarding '%v://%v' locally to '%v://%v' in the workspace\n", spec.listenNetwork, spec.listenAddress, spec.dialNetwork, spec.dialAddress)
186186

@@ -231,7 +231,8 @@ func listenAndPortForwardWireguard(ctx context.Context, cmd *cobra.Command,
231231
go func(netConn net.Conn) {
232232
defer netConn.Close()
233233

234-
ipPort := netaddr.MustParseIPPort(spec.dialAddress).WithIP(agentIP)
234+
port := netip.MustParseAddrPort(spec.dialAddress)
235+
ipPort := netip.AddrPortFrom(agentIP, port.Port())
235236

236237
var remoteConn net.Conn
237238
switch spec.dialNetwork {

coderd/coderd_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99
"net/http"
1010
"net/http/httptest"
11+
"net/netip"
1112
"net/url"
1213
"os"
1314
"strconv"
@@ -22,7 +23,6 @@ import (
2223
"golang.org/x/xerrors"
2324
"google.golang.org/api/idtoken"
2425
"google.golang.org/api/option"
25-
"inet.af/netaddr"
2626
"tailscale.com/tailcfg"
2727

2828
"cdr.dev/slog"
@@ -610,14 +610,14 @@ func TestDERP(t *testing.T) {
610610
}
611611
w1IP := tailnet.IP()
612612
w1, err := tailnet.New(&tailnet.Options{
613-
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(w1IP, 128)},
613+
Addresses: []netip.Prefix{netip.PrefixFrom(w1IP, 128)},
614614
Logger: logger.Named("w1"),
615615
DERPMap: derpMap,
616616
})
617617
require.NoError(t, err)
618618

619619
w2, err := tailnet.New(&tailnet.Options{
620-
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(tailnet.IP(), 128)},
620+
Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.IP(), 128)},
621621
Logger: logger.Named("w2"),
622622
DERPMap: derpMap,
623623
})
@@ -642,7 +642,7 @@ func TestDERP(t *testing.T) {
642642
}()
643643

644644
<-conn
645-
nc, err := w2.DialContextTCP(context.Background(), netaddr.IPPortFrom(w1IP, 35565))
645+
nc, err := w2.DialContextTCP(context.Background(), netip.AddrPortFrom(w1IP, 35565))
646646
require.NoError(t, err)
647647
_ = nc.Close()
648648
<-conn

coderd/database/queries.sql.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspaceagents.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import (
99
"io"
1010
"net"
1111
"net/http"
12+
"net/netip"
1213
"strconv"
1314
"time"
1415

1516
"github.com/google/uuid"
1617
"github.com/hashicorp/yamux"
17-
"github.com/tabbed/pqtype"
1818
"golang.org/x/xerrors"
19-
"inet.af/netaddr"
2019
"nhooyr.io/websocket"
2120
"nhooyr.io/websocket/wsjson"
2221

@@ -614,19 +613,6 @@ func convertApps(dbApps []database.WorkspaceApp) []codersdk.WorkspaceApp {
614613
return apps
615614
}
616615

617-
func inetToNetaddr(inet pqtype.Inet) netaddr.IPPrefix {
618-
if !inet.Valid {
619-
return netaddr.IPPrefixFrom(netaddr.IPv6Unspecified(), 128)
620-
}
621-
622-
ipp, ok := netaddr.FromStdIPNet(&inet.IPNet)
623-
if !ok {
624-
return netaddr.IPPrefixFrom(netaddr.IPv6Unspecified(), 128)
625-
}
626-
627-
return ipp
628-
}
629-
630616
func convertWorkspaceAgent(dbAgent database.WorkspaceAgent, apps []codersdk.WorkspaceApp, agentInactiveDisconnectTimeout time.Duration) (codersdk.WorkspaceAgent, error) {
631617
var envs map[string]string
632618
if dbAgent.EnvironmentVariables.Valid {
@@ -635,11 +621,11 @@ func convertWorkspaceAgent(dbAgent database.WorkspaceAgent, apps []codersdk.Work
635621
return codersdk.WorkspaceAgent{}, xerrors.Errorf("unmarshal: %w", err)
636622
}
637623
}
638-
ips := make([]netaddr.IP, 0)
624+
ips := make([]netip.Addr, 0)
639625
for _, ip := range dbAgent.IPAddresses {
640626
var ipData [16]byte
641627
copy(ipData[:], []byte(ip.IPNet.IP))
642-
ips = append(ips, netaddr.IPFrom16(ipData))
628+
ips = append(ips, netip.AddrFrom16(ipData))
643629
}
644630
workspaceAgent := codersdk.WorkspaceAgent{
645631
ID: dbAgent.ID,

codersdk/workspaceagents.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"net"
99
"net/http"
1010
"net/http/cookiejar"
11+
"net/netip"
1112

1213
"cloud.google.com/go/compute/metadata"
1314
"github.com/google/uuid"
1415
"github.com/hashicorp/yamux"
1516
"github.com/pion/webrtc/v3"
1617
"golang.org/x/net/proxy"
1718
"golang.org/x/xerrors"
18-
"inet.af/netaddr"
1919
"nhooyr.io/websocket"
2020
"nhooyr.io/websocket/wsjson"
2121
"tailscale.com/tailcfg"
@@ -317,10 +317,10 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, agentID uuid.UUI
317317
if err != nil {
318318
return nil, xerrors.Errorf("decode derpmap: %w", err)
319319
}
320-
ip := tailnet.IP()
321320

321+
ip := tailnet.IP()
322322
server, err := tailnet.New(&tailnet.Options{
323-
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(ip, 128)},
323+
Addresses: []netip.Prefix{netip.PrefixFrom(ip, 128)},
324324
DERPMap: &derpMap,
325325
Logger: logger,
326326
})
@@ -342,9 +342,9 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, agentID uuid.UUI
342342
if err != nil {
343343
return nil, xerrors.Errorf("get workspace agent: %w", err)
344344
}
345-
ipRanges := make([]netaddr.IPPrefix, 0, len(workspaceAgent.IPAddresses))
345+
ipRanges := make([]netip.Prefix, 0, len(workspaceAgent.IPAddresses))
346346
for _, address := range workspaceAgent.IPAddresses {
347-
ipRanges = append(ipRanges, netaddr.IPPrefixFrom(address, 128))
347+
ipRanges = append(ipRanges, netip.PrefixFrom(address, 128))
348348
}
349349
agentNode := &tailnet.Node{
350350
Key: workspaceAgent.NodePublicKey,

codersdk/workspaceresources.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"net/netip"
89
"time"
910

1011
"github.com/google/uuid"
11-
"inet.af/netaddr"
1212
"tailscale.com/types/key"
1313
)
1414

@@ -56,7 +56,7 @@ type WorkspaceAgent struct {
5656
Apps []WorkspaceApp `json:"apps"`
5757

5858
// For internal routing only.
59-
IPAddresses []netaddr.IP `json:"ip_addresses"`
59+
IPAddresses []netip.Addr `json:"ip_addresses"`
6060
NodePublicKey key.NodePublic `json:"node_public_key"`
6161
DiscoPublicKey key.DiscoPublic `json:"disco_public_key"`
6262
// PreferredDERP represents the connected region.

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ require (
141141
gopkg.in/natefinch/lumberjack.v2 v2.0.0
142142
gopkg.in/yaml.v3 v3.0.1
143143
gvisor.dev/gvisor v0.0.0-20220801230058-850e42eb4444
144-
inet.af/netaddr v0.0.0-20220617031823-097006376321
145144
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
146145
nhooyr.io/websocket v1.8.7
147146
storj.io/drpc v0.0.33-0.20220622181519-9206537a4db7
@@ -281,10 +280,8 @@ require (
281280
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.8.0 // indirect
282281
go.opentelemetry.io/otel/metric v0.31.0 // indirect
283282
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
284-
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
285283
go4.org/mem v0.0.0-20210711025021-927187094b94 // indirect
286-
go4.org/netipx v0.0.0-20220725152314-7e7bdc8411bf // indirect
287-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
284+
go4.org/netipx v0.0.0-20220725152314-7e7bdc8411bf
288285
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
289286
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
290287
golang.zx2c4.com/wireguard/windows v0.4.10 // indirect

0 commit comments

Comments
 (0)