fix(machines): use ListAllMachines function

added a simple filter to remove the current node
This commit is contained in:
Adrien Raffin-Caboisse 2022-02-21 09:05:04 +01:00
parent 960412a335
commit 9c6ce02554

View File

@ -154,10 +154,9 @@ func (h *Headscale) getFilteredByACLPeers(machine *Machine) (Machines, error) {
Str("machine", machine.Name). Str("machine", machine.Name).
Msg("Finding peers filtered by ACLs") Msg("Finding peers filtered by ACLs")
machines := Machines{} machines, err := h.ListAllMachines()
if err := h.db.Preload("Namespace").Where("machine_key <> ? AND registered", if err != nil {
machine.MachineKey).Find(&machines).Error; err != nil { log.Error().Err(err).Msg("Error retrieving list of machines")
log.Error().Err(err).Msg("Error accessing db")
return Machines{}, err return Machines{}, err
} }
peers := make(map[uint64]Machine) peers := make(map[uint64]Machine)
@ -180,6 +179,9 @@ func (h *Headscale) getFilteredByACLPeers(machine *Machine) (Machines, error) {
// how to talk to node A and then add the peering resource. // how to talk to node A and then add the peering resource.
for _, peer := range machines { for _, peer := range machines {
if peer.ID == machine.ID {
continue
}
for _, rule := range h.aclRules { for _, rule := range h.aclRules {
var dst []string var dst []string
for _, d := range rule.DstPorts { for _, d := range rule.DstPorts {