mirror of
https://github.com/h44z/wg-portal.git
synced 2026-05-28 08:56:17 +00:00
Fix single-peer interface import mode (#695)
Co-authored-by: nbk1982 <16351736+nbk1982@users.noreply.github.com>
This commit is contained in:
@@ -893,16 +893,7 @@ func (m Manager) importInterface(
|
||||
}
|
||||
}
|
||||
|
||||
// try to predict the interface type based on the number of peers
|
||||
switch len(peers) {
|
||||
case 0:
|
||||
iface.Type = domain.InterfaceTypeAny // no peers means this is an unknown interface
|
||||
case 1:
|
||||
iface.Type = domain.InterfaceTypeClient // one peer means this is a client interface
|
||||
default: // multiple peers means this is a server interface
|
||||
|
||||
iface.Type = domain.InterfaceTypeServer
|
||||
}
|
||||
iface.Type = inferImportedInterfaceType(iface, peers)
|
||||
|
||||
existingInterface, err := m.db.GetInterface(ctx, iface.Identifier)
|
||||
if err != nil && !errors.Is(err, domain.ErrNotFound) {
|
||||
@@ -930,6 +921,20 @@ func (m Manager) importInterface(
|
||||
return nil
|
||||
}
|
||||
|
||||
func inferImportedInterfaceType(iface *domain.Interface, peers []domain.PhysicalPeer) domain.InterfaceType {
|
||||
switch len(peers) {
|
||||
case 0:
|
||||
return domain.InterfaceTypeAny // no peers means this is an unknown interface
|
||||
case 1:
|
||||
if iface.ListenPort > 0 {
|
||||
return domain.InterfaceTypeServer // a listening interface with one peer is commonly a site-to-site server
|
||||
}
|
||||
return domain.InterfaceTypeClient
|
||||
default: // multiple peers means this is a server interface
|
||||
return domain.InterfaceTypeServer
|
||||
}
|
||||
}
|
||||
|
||||
// extractPfsenseDefaultsFromPeers extracts common endpoint and DNS information from peers
|
||||
// For server interfaces, peers typically have endpoints pointing to the server, so we use the most common one
|
||||
func extractPfsenseDefaultsFromPeers(peers []domain.PhysicalPeer, listenPort int) (endpoint, dns string) {
|
||||
|
||||
Reference in New Issue
Block a user