Jit of aliases working

This commit is contained in:
Owen
2026-03-12 17:26:46 -07:00
parent e326da3d3e
commit c2b5ef96a4
4 changed files with 39 additions and 23 deletions

View File

@@ -745,6 +745,7 @@ func (p *DNSProxy) SetJITHandler(handler func(siteId int)) {
// domain should be a domain name (e.g., "example.com" or "example.com.") // domain should be a domain name (e.g., "example.com" or "example.com.")
// ip should be a valid IPv4 or IPv6 address // ip should be a valid IPv4 or IPv6 address
func (p *DNSProxy) AddDNSRecord(domain string, ip net.IP, siteId int) error { func (p *DNSProxy) AddDNSRecord(domain string, ip net.IP, siteId int) error {
logger.Debug("Adding dns record for domain %s with IP %s (siteId=%d)", domain, ip.String(), siteId)
return p.recordStore.AddRecord(domain, ip, siteId) return p.recordStore.AddRecord(domain, ip, siteId)
} }

View File

@@ -75,8 +75,18 @@ func (s *DNSRecordStore) AddRecord(domain string, ip net.IP, siteId int) error {
} }
rs := m[domain] rs := m[domain]
if isV4 { if isV4 {
for _, existing := range rs.A {
if existing.Equal(ip) {
return nil
}
}
rs.A = append(rs.A, ip) rs.A = append(rs.A, ip)
} else { } else {
for _, existing := range rs.AAAA {
if existing.Equal(ip) {
return nil
}
}
rs.AAAA = append(rs.AAAA, ip) rs.AAAA = append(rs.AAAA, ip)
} }
@@ -87,6 +97,7 @@ func (s *DNSRecordStore) AddRecord(domain string, ip net.IP, siteId int) error {
return nil return nil
} }
// AddPTRRecord adds a PTR record mapping an IP address to a domain name // AddPTRRecord adds a PTR record mapping an IP address to a domain name
// ip should be a valid IPv4 or IPv6 address // ip should be a valid IPv4 or IPv6 address
// domain should be in FQDN format (e.g., "example.com.") // domain should be in FQDN format (e.g., "example.com.")

View File

@@ -175,11 +175,7 @@ func (o *Olm) handleConnect(msg websocket.WSMessage) {
for i := range wgData.Sites { for i := range wgData.Sites {
site := wgData.Sites[i] site := wgData.Sites[i]
if site.PublicKey == "" { if site.PublicKey != "" {
logger.Warn("Skipping site %d (%s): no public key available (site may not be connected)", site.SiteId, site.Name)
continue
}
var siteEndpoint string var siteEndpoint string
// here we are going to take the relay endpoint if it exists which means we requested a relay for this peer // here we are going to take the relay endpoint if it exists which means we requested a relay for this peer
if site.RelayEndpoint != "" { if site.RelayEndpoint != "" {
@@ -189,7 +185,9 @@ func (o *Olm) handleConnect(msg websocket.WSMessage) {
} }
o.apiServer.AddPeerStatus(site.SiteId, site.Name, false, 0, siteEndpoint, false) o.apiServer.AddPeerStatus(site.SiteId, site.Name, false, 0, siteEndpoint, false)
}
// we still call this to add the aliases for jit lookup but we just do that then pass inside. need to skip the above so we dont add to the api
if err := o.peerManager.AddPeer(site); err != nil { if err := o.peerManager.AddPeer(site); err != nil {
logger.Error("Failed to add peer: %v", err) logger.Error("Failed to add peer: %v", err)
return return

View File

@@ -111,6 +111,19 @@ func (pm *PeerManager) AddPeer(siteConfig SiteConfig) error {
pm.mu.Lock() pm.mu.Lock()
defer pm.mu.Unlock() defer pm.mu.Unlock()
for _, alias := range siteConfig.Aliases {
address := net.ParseIP(alias.AliasAddress)
if address == nil {
continue
}
pm.dnsProxy.AddDNSRecord(alias.Alias, address, siteConfig.SiteId)
}
if siteConfig.PublicKey == "" {
logger.Debug("Skip adding site %d because no pub key", siteConfig.SiteId)
return nil
}
// build the allowed IPs list from the remote subnets and aliases and add them to the peer // build the allowed IPs list from the remote subnets and aliases and add them to the peer
allowedIPs := make([]string, 0, len(siteConfig.RemoteSubnets)+len(siteConfig.Aliases)) allowedIPs := make([]string, 0, len(siteConfig.RemoteSubnets)+len(siteConfig.Aliases))
allowedIPs = append(allowedIPs, siteConfig.RemoteSubnets...) allowedIPs = append(allowedIPs, siteConfig.RemoteSubnets...)
@@ -143,13 +156,6 @@ func (pm *PeerManager) AddPeer(siteConfig SiteConfig) error {
if err := network.AddRoutes(siteConfig.RemoteSubnets, pm.interfaceName); err != nil { if err := network.AddRoutes(siteConfig.RemoteSubnets, pm.interfaceName); err != nil {
logger.Error("Failed to add routes for remote subnets: %v", err) logger.Error("Failed to add routes for remote subnets: %v", err)
} }
for _, alias := range siteConfig.Aliases {
address := net.ParseIP(alias.AliasAddress)
if address == nil {
continue
}
pm.dnsProxy.AddDNSRecord(alias.Alias, address, siteConfig.SiteId)
}
monitorAddress := strings.Split(siteConfig.ServerIP, "/")[0] monitorAddress := strings.Split(siteConfig.ServerIP, "/")[0]
monitorPeer := net.JoinHostPort(monitorAddress, strconv.Itoa(int(siteConfig.ServerPort+1))) // +1 for the monitor port monitorPeer := net.JoinHostPort(monitorAddress, strconv.Itoa(int(siteConfig.ServerPort+1))) // +1 for the monitor port