Another bunch of gosec/golint related fixes

This commit is contained in:
Juan Font 2022-11-25 15:37:10 +00:00
parent b5f1ae3d90
commit 37a031d13e
2 changed files with 16 additions and 16 deletions

View File

@ -1105,9 +1105,9 @@ func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) error {
} }
} }
for _, approvedRoute := range approvedRoutes { for i, approvedRoute := range approvedRoutes {
approvedRoute.Enabled = true approvedRoutes[i].Enabled = true
err = h.db.Save(&approvedRoute).Error err = h.db.Save(&approvedRoutes[i]).Error
if err != nil { if err != nil {
log.Err(err). log.Err(err).
Str("approvedRoute", approvedRoute.String()). Str("approvedRoute", approvedRoute.String()).

View File

@ -106,20 +106,20 @@ func (h *Headscale) processMachineRoutes(machine *Machine) error {
advertisedRoutes[prefix] = false advertisedRoutes[prefix] = false
} }
for _, route := range currentRoutes { for pos, route := range currentRoutes {
if _, ok := advertisedRoutes[netip.Prefix(route.Prefix)]; ok { if _, ok := advertisedRoutes[netip.Prefix(route.Prefix)]; ok {
if !route.Advertised { if !route.Advertised {
route.Advertised = true currentRoutes[pos].Advertised = true
err := h.db.Save(&route).Error err := h.db.Save(&currentRoutes[pos]).Error
if err != nil { if err != nil {
return err return err
} }
} }
advertisedRoutes[netip.Prefix(route.Prefix)] = true advertisedRoutes[netip.Prefix(route.Prefix)] = true
} else if route.Advertised { } else if route.Advertised {
route.Advertised = false currentRoutes[pos].Advertised = false
route.Enabled = false currentRoutes[pos].Enabled = false
err := h.db.Save(&route).Error err := h.db.Save(&currentRoutes[pos]).Error
if err != nil { if err != nil {
return err return err
} }
@ -155,7 +155,7 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
log.Error().Err(err).Msg("error getting routes") log.Error().Err(err).Msg("error getting routes")
} }
for _, route := range routes { for pos, route := range routes {
if route.isExitRoute() { if route.isExitRoute() {
continue continue
} }
@ -163,8 +163,8 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
if !route.IsPrimary { if !route.IsPrimary {
_, err := h.getPrimaryRoute(netip.Prefix(route.Prefix)) _, err := h.getPrimaryRoute(netip.Prefix(route.Prefix))
if h.isUniquePrefix(route) || errors.Is(err, gorm.ErrRecordNotFound) { if h.isUniquePrefix(route) || errors.Is(err, gorm.ErrRecordNotFound) {
route.IsPrimary = true routes[pos].IsPrimary = true
err := h.db.Save(&route).Error err := h.db.Save(&routes[pos]).Error
if err != nil { if err != nil {
log.Error().Err(err).Msg("error marking route as primary") log.Error().Err(err).Msg("error marking route as primary")
@ -202,9 +202,9 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
} }
var newPrimaryRoute *Route var newPrimaryRoute *Route
for _, r := range newPrimaryRoutes { for pos, r := range newPrimaryRoutes {
if r.Machine.isOnline() { if r.Machine.isOnline() {
newPrimaryRoute = &r newPrimaryRoute = &newPrimaryRoutes[pos]
break break
} }
@ -226,8 +226,8 @@ func (h *Headscale) handlePrimarySubnetFailover() error {
Msgf("found new primary route") Msgf("found new primary route")
// disable the old primary route // disable the old primary route
route.IsPrimary = false routes[pos].IsPrimary = false
err = h.db.Save(&route).Error err = h.db.Save(&routes[pos]).Error
if err != nil { if err != nil {
log.Error().Err(err).Msg("error disabling old primary route") log.Error().Err(err).Msg("error disabling old primary route")