Peer interface address should match server's prefix length (#177)

This commit is contained in:
Ruoxi Wang 2023-10-20 04:53:51 +08:00 committed by GitHub
parent 40cfcd67e9
commit 4c061a1aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View File

@ -644,7 +644,7 @@ func (m Manager) importPeer(ctx context.Context, in *domain.Interface, p *domain
peer.InterfaceIdentifier = in.Identifier peer.InterfaceIdentifier = in.Identifier
peer.EndpointPublicKey = domain.StringConfigOption{Value: in.PublicKey, Overridable: true} peer.EndpointPublicKey = domain.StringConfigOption{Value: in.PublicKey, Overridable: true}
peer.AllowedIPsStr = domain.StringConfigOption{Value: in.PeerDefAllowedIPsStr, Overridable: true} peer.AllowedIPsStr = domain.StringConfigOption{Value: in.PeerDefAllowedIPsStr, Overridable: true}
peer.Interface.Addresses = p.AllowedIPs // use allowed IP's as the peer IP's peer.Interface.Addresses = p.AllowedIPs // use allowed IP's as the peer IP's TODO: Should this also match server interface address' prefix length?
peer.Interface.DnsStr = domain.StringConfigOption{Value: in.PeerDefDnsStr, Overridable: true} peer.Interface.DnsStr = domain.StringConfigOption{Value: in.PeerDefDnsStr, Overridable: true}
peer.Interface.DnsSearchStr = domain.StringConfigOption{Value: in.PeerDefDnsSearchStr, Overridable: true} peer.Interface.DnsSearchStr = domain.StringConfigOption{Value: in.PeerDefDnsSearchStr, Overridable: true}
peer.Interface.Mtu = domain.IntConfigOption{Value: in.PeerDefMtu, Overridable: true} peer.Interface.Mtu = domain.IntConfigOption{Value: in.PeerDefMtu, Overridable: true}

View File

@ -310,8 +310,9 @@ func (m Manager) getFreshPeerIpConfig(ctx context.Context, iface *domain.Interfa
for { for {
ipConflict := false ipConflict := false
for _, usedIp := range existingIps[network] { for _, usedIp := range existingIps[network] {
if usedIp == ip { if usedIp.Addr == ip.Addr {
ipConflict = true ipConflict = true
break
} }
} }
@ -326,7 +327,7 @@ func (m Manager) getFreshPeerIpConfig(ctx context.Context, iface *domain.Interfa
} }
} }
ips = append(ips, ip.HostAddr()) ips = append(ips, ip)
} }
return return

View File

@ -103,7 +103,9 @@ func (i *Interface) GetAllowedIPs(peers []Peer) []Cidr {
var allowedCidrs []Cidr var allowedCidrs []Cidr
for _, peer := range peers { for _, peer := range peers {
allowedCidrs = append(allowedCidrs, peer.Interface.Addresses...) for _, ip := range peer.Interface.Addresses {
allowedCidrs = append(allowedCidrs, ip.HostAddr())
}
if peer.ExtraAllowedIPsStr != "" { if peer.ExtraAllowedIPsStr != "" {
extraIPs, err := CidrsFromString(peer.ExtraAllowedIPsStr) extraIPs, err := CidrsFromString(peer.ExtraAllowedIPsStr)
if err == nil { if err == nil {

View File

@ -228,7 +228,10 @@ func MergeToPhysicalPeer(pp *PhysicalPeer, p *Peer) {
extraAllowedIPs, _ := CidrsFromString(p.ExtraAllowedIPsStr) extraAllowedIPs, _ := CidrsFromString(p.ExtraAllowedIPsStr)
pp.AllowedIPs = append(allowedIPs, extraAllowedIPs...) pp.AllowedIPs = append(allowedIPs, extraAllowedIPs...)
} else { } else {
allowedIPs := p.Interface.Addresses allowedIPs := make([]Cidr, len(p.Interface.Addresses))
for i, ip := range p.Interface.Addresses {
allowedIPs[i] = ip.HostAddr()
}
extraAllowedIPs, _ := CidrsFromString(p.ExtraAllowedIPsStr) extraAllowedIPs, _ := CidrsFromString(p.ExtraAllowedIPsStr)
pp.AllowedIPs = append(allowedIPs, extraAllowedIPs...) pp.AllowedIPs = append(allowedIPs, extraAllowedIPs...)
} }