mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
Another bunch of gosec/golint related fixes
This commit is contained in:
parent
b5f1ae3d90
commit
37a031d13e
@ -1105,9 +1105,9 @@ func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, approvedRoute := range approvedRoutes {
|
||||
approvedRoute.Enabled = true
|
||||
err = h.db.Save(&approvedRoute).Error
|
||||
for i, approvedRoute := range approvedRoutes {
|
||||
approvedRoutes[i].Enabled = true
|
||||
err = h.db.Save(&approvedRoutes[i]).Error
|
||||
if err != nil {
|
||||
log.Err(err).
|
||||
Str("approvedRoute", approvedRoute.String()).
|
||||
|
26
routes.go
26
routes.go
@ -106,20 +106,20 @@ func (h *Headscale) processMachineRoutes(machine *Machine) error {
|
||||
advertisedRoutes[prefix] = false
|
||||
}
|
||||
|
||||
for _, route := range currentRoutes {
|
||||
for pos, route := range currentRoutes {
|
||||
if _, ok := advertisedRoutes[netip.Prefix(route.Prefix)]; ok {
|
||||
if !route.Advertised {
|
||||
route.Advertised = true
|
||||
err := h.db.Save(&route).Error
|
||||
currentRoutes[pos].Advertised = true
|
||||
err := h.db.Save(¤tRoutes[pos]).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
advertisedRoutes[netip.Prefix(route.Prefix)] = true
|
||||
} else if route.Advertised {
|
||||
route.Advertised = false
|
||||
route.Enabled = false
|
||||
err := h.db.Save(&route).Error
|
||||
currentRoutes[pos].Advertised = false
|
||||
currentRoutes[pos].Enabled = false
|
||||
err := h.db.Save(¤tRoutes[pos]).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -155,7 +155,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
|
||||
log.Error().Err(err).Msg("error getting routes")
|
||||
}
|
||||
|
||||
for _, route := range routes {
|
||||
for pos, route := range routes {
|
||||
if route.isExitRoute() {
|
||||
continue
|
||||
}
|
||||
@ -163,8 +163,8 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
|
||||
if !route.IsPrimary {
|
||||
_, err := h.getPrimaryRoute(netip.Prefix(route.Prefix))
|
||||
if h.isUniquePrefix(route) || errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
route.IsPrimary = true
|
||||
err := h.db.Save(&route).Error
|
||||
routes[pos].IsPrimary = true
|
||||
err := h.db.Save(&routes[pos]).Error
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error marking route as primary")
|
||||
|
||||
@ -202,9 +202,9 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
|
||||
}
|
||||
|
||||
var newPrimaryRoute *Route
|
||||
for _, r := range newPrimaryRoutes {
|
||||
for pos, r := range newPrimaryRoutes {
|
||||
if r.Machine.isOnline() {
|
||||
newPrimaryRoute = &r
|
||||
newPrimaryRoute = &newPrimaryRoutes[pos]
|
||||
|
||||
break
|
||||
}
|
||||
@ -226,8 +226,8 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
|
||||
Msgf("found new primary route")
|
||||
|
||||
// disable the old primary route
|
||||
route.IsPrimary = false
|
||||
err = h.db.Save(&route).Error
|
||||
routes[pos].IsPrimary = false
|
||||
err = h.db.Save(&routes[pos]).Error
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error disabling old primary route")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user