Former-commit-id: 307b82e053
This commit is contained in:
Owen
2025-11-23 18:07:12 -05:00
parent 9099b246dc
commit 24b5122cc1
4 changed files with 36 additions and 46 deletions

View File

@@ -52,7 +52,6 @@ type TunnelConfig struct {
// Network settings
MTU int
DNS string
DNSProxyIP string
UpstreamDNS []string
InterfaceName string
@@ -131,7 +130,6 @@ func Init(ctx context.Context, config GlobalConfig) {
UserToken: req.UserToken,
MTU: req.MTU,
DNS: req.DNS,
DNSProxyIP: req.DNSProxyIP,
UpstreamDNS: req.UpstreamDNS,
InterfaceName: req.InterfaceName,
Holepunch: req.Holepunch,
@@ -487,26 +485,18 @@ func StartTunnel(config TunnelConfig) {
logger.Error("Failed to bring up WireGuard device: %v", err)
}
if config.DNSProxyIP != "" {
// Create and start DNS proxy
dnsProxy, err = dns.NewDNSProxy(tdev, middleDev, config.MTU, config.DNSProxyIP, config.UpstreamDNS)
if err != nil {
logger.Error("Failed to create DNS proxy: %v", err)
}
if err := dnsProxy.Start(); err != nil {
logger.Error("Failed to start DNS proxy: %v", err)
}
// Create and start DNS proxy
dnsProxy, err = dns.NewDNSProxy(tdev, middleDev, config.MTU, wgData.UtilitySubnet, config.UpstreamDNS)
if err != nil {
logger.Error("Failed to create DNS proxy: %v", err)
}
if err = ConfigureInterface(interfaceName, wgData, config.MTU); err != nil {
logger.Error("Failed to configure interface: %v", err)
}
if config.DNSProxyIP != "" {
if addRoutes([]string{config.DNSProxyIP + "/32"}, interfaceName); err != nil {
logger.Error("Failed to add route for DNS server: %v", err)
}
if addRoutes([]string{wgData.UtilitySubnet}, interfaceName); err != nil { // also route the utility subnet
logger.Error("Failed to add route for utility subnet: %v", err)
}
// TODO: seperate adding the callback to this so we can init it above with the interface
@@ -565,16 +555,14 @@ func StartTunnel(config TunnelConfig) {
}
for _, alias := range site.Aliases {
if dnsProxy != nil { // some times this is not initialized
// try to parse the alias address into net.IP
address := net.ParseIP(alias.AliasAddress)
if address == nil {
logger.Warn("Invalid alias address for %s: %s", alias.Alias, alias.AliasAddress)
continue
}
dnsProxy.AddDNSRecord(alias.Alias, address)
// try to parse the alias address into net.IP
address := net.ParseIP(alias.AliasAddress)
if address == nil {
logger.Warn("Invalid alias address for %s: %s", alias.Alias, alias.AliasAddress)
continue
}
dnsProxy.AddDNSRecord(alias.Alias, address)
}
logger.Info("Configured peer %s", site.PublicKey)
@@ -582,6 +570,10 @@ func StartTunnel(config TunnelConfig) {
peerMonitor.Start()
if err := dnsProxy.Start(); err != nil {
logger.Error("Failed to start DNS proxy: %v", err)
}
apiServer.SetRegistered(true)
connected = true