mirror of
https://github.com/fosrl/olm.git
synced 2026-03-13 14:16:41 +00:00
Jit of aliases working
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.")
|
||||||
|
|||||||
@@ -175,21 +175,19 @@ 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)
|
var siteEndpoint string
|
||||||
continue
|
// here we are going to take the relay endpoint if it exists which means we requested a relay for this peer
|
||||||
|
if site.RelayEndpoint != "" {
|
||||||
|
siteEndpoint = site.RelayEndpoint
|
||||||
|
} else {
|
||||||
|
siteEndpoint = site.Endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
o.apiServer.AddPeerStatus(site.SiteId, site.Name, false, 0, siteEndpoint, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
var siteEndpoint string
|
// 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
|
||||||
// here we are going to take the relay endpoint if it exists which means we requested a relay for this peer
|
|
||||||
if site.RelayEndpoint != "" {
|
|
||||||
siteEndpoint = site.RelayEndpoint
|
|
||||||
} else {
|
|
||||||
siteEndpoint = site.Endpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
o.apiServer.AddPeerStatus(site.SiteId, site.Name, false, 0, siteEndpoint, false)
|
|
||||||
|
|
||||||
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
|
||||||
@@ -311,12 +309,12 @@ func (o *Olm) handleTerminate(msg websocket.WSMessage) {
|
|||||||
logger.Error("Error unmarshaling terminate error data: %v", err)
|
logger.Error("Error unmarshaling terminate error data: %v", err)
|
||||||
} else {
|
} else {
|
||||||
logger.Info("Terminate reason (code: %s): %s", errorData.Code, errorData.Message)
|
logger.Info("Terminate reason (code: %s): %s", errorData.Code, errorData.Message)
|
||||||
|
|
||||||
if errorData.Code == "TERMINATED_INACTIVITY" {
|
if errorData.Code == "TERMINATED_INACTIVITY" {
|
||||||
logger.Info("Ignoring...")
|
logger.Info("Ignoring...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the olm error in the API server so it can be exposed via status
|
// Set the olm error in the API server so it can be exposed via status
|
||||||
o.apiServer.SetOlmError(errorData.Code, errorData.Message)
|
o.apiServer.SetOlmError(errorData.Code, errorData.Message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,19 @@ func (pm *PeerManager) GetAllPeers() []SiteConfig {
|
|||||||
func (pm *PeerManager) AddPeer(siteConfig SiteConfig) error {
|
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))
|
||||||
@@ -143,14 +156,7 @@ 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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user