reconfig computes the correct wireguard config and calls the engine.Reconfig with the config we have. It is not intended for this to be called outside of the updateLoop()
(nm *netmap.NetworkMap, hosts map[dnsname.FQDN][]netip.Addr)
| 343 | // with the config we have. It is not intended for this to be called outside of |
| 344 | // the updateLoop() |
| 345 | func (c *configMaps) reconfig(nm *netmap.NetworkMap, hosts map[dnsname.FQDN][]netip.Addr) { |
| 346 | dnsCfg := &dns.Config{} |
| 347 | if len(hosts) > 0 { |
| 348 | dnsCfg.Hosts = hosts |
| 349 | dnsCfg.OnlyIPv6 = true |
| 350 | dnsCfg.Routes = map[dnsname.FQDN][]*dnstype.Resolver{ |
| 351 | c.matchDomain: nil, |
| 352 | } |
| 353 | } |
| 354 | cfg, err := nmcfg.WGCfg(nm, Logger(c.logger.Named("net.wgconfig")), netmap.AllowSingleHosts, "") |
| 355 | if err != nil { |
| 356 | // WGCfg never returns an error at the time this code was written. If it starts, returning |
| 357 | // errors if/when we upgrade tailscale, we'll need to deal. |
| 358 | c.logger.Critical(context.Background(), "update wireguard config failed", slog.Error(err)) |
| 359 | return |
| 360 | } |
| 361 | |
| 362 | rc := &router.Config{ |
| 363 | LocalAddrs: nm.Addresses, |
| 364 | Routes: []netip.Prefix{CoderServicePrefix.AsNetip()}, |
| 365 | } |
| 366 | err = c.engine.Reconfig(cfg, rc, dnsCfg, &tailcfg.Debug{}) |
| 367 | if err != nil { |
| 368 | if errors.Is(err, wgengine.ErrNoChanges) { |
| 369 | return |
| 370 | } |
| 371 | c.logger.Error(context.Background(), "failed to reconfigure wireguard engine", slog.Error(err)) |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // filterLocked returns the current filter, based on our local addresses. c.L |
| 376 | // must be held. |