Skip to content

Commit

Permalink
ensure disabled and failover routes are propagated
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Oct 2, 2023
1 parent fe365c9 commit 17f887c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions hscontrol/db/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"errors"
"fmt"
"net/netip"

"github.com/juanfont/headscale/hscontrol/policy"
Expand Down Expand Up @@ -122,6 +123,8 @@ func (hsdb *HSDatabase) DisableRoute(id uint64) error {
return err
}

node := route.Node

// Tailscale requires both IPv4 and IPv6 exit routes to
// be enabled at the same time, as per
// https://github.com/juanfont/headscale/issues/804#issuecomment-1399314002
Expand All @@ -133,6 +136,20 @@ func (hsdb *HSDatabase) DisableRoute(id uint64) error {
return err
}

// Ensure the node has the latest routes when notifying the other
// nodes
nRoutes, err := hsdb.getNodeRoutes(&node)
if err != nil {
return fmt.Errorf("failed to read back routes: %w", err)
}

node.Routes = nRoutes

hsdb.notifier.NotifyAll(types.StateUpdate{
Type: types.StatePeerChanged,
Changed: types.Nodes{&node},
})

return hsdb.handlePrimarySubnetFailover()
}

Expand All @@ -152,6 +169,13 @@ func (hsdb *HSDatabase) DisableRoute(id uint64) error {
}
}

node.Routes = routes

hsdb.notifier.NotifyAll(types.StateUpdate{
Type: types.StatePeerChanged,
Changed: types.Nodes{&node},
})

return hsdb.handlePrimarySubnetFailover()
}

Expand Down Expand Up @@ -363,6 +387,15 @@ func (hsdb *HSDatabase) handlePrimarySubnetFailover() error {
return err
}

// Ensure the node has the latest routes when notifying the other
// nodes
nRoutes, err := hsdb.getNodeRoutes(node)
if err != nil {
return fmt.Errorf("failed to read back routes: %w", err)
}

node.Routes = nRoutes

changedNodes = append(changedNodes, node)

continue
Expand Down Expand Up @@ -437,10 +470,24 @@ func (hsdb *HSDatabase) handlePrimarySubnetFailover() error {
return err
}

// Ensure the node has the latest routes when notifying the other
// nodes
nRoutes, err := hsdb.getNodeRoutes(node)
if err != nil {
return fmt.Errorf("failed to read back routes: %w", err)
}

node.Routes = nRoutes

changedNodes = append(changedNodes, node)
}
}

log.Trace().
Caller().
Interface("changed_nodes", changedNodes).
Msg("notifying nodes after route change")

if len(changedNodes) > 0 {
hsdb.notifier.NotifyAll(types.StateUpdate{
Type: types.StatePeerChanged,
Expand Down

0 comments on commit 17f887c

Please sign in to comment.