@@ -64,6 +64,7 @@ type Options struct {
64
64
SSHMaxTimeout time.Duration
65
65
TailnetListenPort uint16
66
66
Subsystem codersdk.AgentSubsystem
67
+ Addresses []netip.Prefix
67
68
68
69
PrometheusRegistry * prometheus.Registry
69
70
}
@@ -111,6 +112,16 @@ func New(options Options) Agent {
111
112
prometheusRegistry = prometheus .NewRegistry ()
112
113
}
113
114
115
+ if len (options .Addresses ) == 0 {
116
+ options .Addresses = []netip.Prefix {
117
+ // This is the IP that should be used primarily.
118
+ netip .PrefixFrom (tailnet .IP (), 128 ),
119
+ // We also listen on the legacy codersdk.WorkspaceAgentIP. This
120
+ // allows for a transition away from wsconncache.
121
+ netip .PrefixFrom (codersdk .WorkspaceAgentIP , 128 ),
122
+ }
123
+ }
124
+
114
125
ctx , cancelFunc := context .WithCancel (context .Background ())
115
126
a := & agent {
116
127
tailnetListenPort : options .TailnetListenPort ,
@@ -131,6 +142,7 @@ func New(options Options) Agent {
131
142
connStatsChan : make (chan * agentsdk.Stats , 1 ),
132
143
sshMaxTimeout : options .SSHMaxTimeout ,
133
144
subsystem : options .Subsystem ,
145
+ addresses : options .Addresses ,
134
146
135
147
prometheusRegistry : prometheusRegistry ,
136
148
metrics : newAgentMetrics (prometheusRegistry ),
@@ -174,6 +186,7 @@ type agent struct {
174
186
lifecycleStates []agentsdk.PostLifecycleRequest
175
187
176
188
network * tailnet.Conn
189
+ addresses []netip.Prefix
177
190
connStatsChan chan * agentsdk.Stats
178
191
latestStat atomic.Pointer [agentsdk.Stats ]
179
192
@@ -639,7 +652,7 @@ func (a *agent) trackConnGoroutine(fn func()) error {
639
652
640
653
func (a * agent ) createTailnet (ctx context.Context , derpMap * tailcfg.DERPMap , disableDirectConnections bool ) (_ * tailnet.Conn , err error ) {
641
654
network , err := tailnet .NewConn (& tailnet.Options {
642
- Addresses : []netip. Prefix { netip . PrefixFrom ( codersdk . WorkspaceAgentIP , 128 )} ,
655
+ Addresses : a . addresses ,
643
656
DERPMap : derpMap ,
644
657
Logger : a .logger .Named ("tailnet" ),
645
658
ListenPort : a .tailnetListenPort ,
0 commit comments