diff --git a/hscontrol/db/routes.go b/hscontrol/db/routes.go index dcf00bcb..8ee91d6b 100644 --- a/hscontrol/db/routes.go +++ b/hscontrol/db/routes.go @@ -585,6 +585,10 @@ func (hsdb *HSDatabase) failoverRoute(r *types.Route) ([]key.MachinePublic, erro continue } + if !route.Enabled { + continue + } + if hsdb.notifier.IsConnected(route.Node.MachineKey) { newPrimary = &routes[idx] break diff --git a/hscontrol/db/routes_test.go b/hscontrol/db/routes_test.go index d491b6a3..15456071 100644 --- a/hscontrol/db/routes_test.go +++ b/hscontrol/db/routes_test.go @@ -371,6 +371,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, routes: types.Routes{ types.Route{ @@ -382,6 +383,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, types.Route{ Model: gorm.Model{ @@ -392,6 +394,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[1], }, IsPrimary: false, + Enabled: true, }, }, want: []key.MachinePublic{ @@ -411,6 +414,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: false, + Enabled: true, }, routes: types.Routes{ types.Route{ @@ -422,6 +426,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, types.Route{ Model: gorm.Model{ @@ -432,6 +437,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[1], }, IsPrimary: false, + Enabled: true, }, }, want: nil, @@ -448,6 +454,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[1], }, IsPrimary: true, + Enabled: true, }, routes: types.Routes{ types.Route{ @@ -459,6 +466,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: false, + Enabled: true, }, types.Route{ Model: gorm.Model{ @@ -469,6 +477,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[1], }, IsPrimary: true, + Enabled: true, }, types.Route{ Model: gorm.Model{ @@ -479,6 +488,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[2], }, IsPrimary: false, + Enabled: true, }, }, want: []key.MachinePublic{ @@ -498,6 +508,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, routes: types.Routes{ types.Route{ @@ -509,6 +520,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, // Offline types.Route{ @@ -520,6 +532,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[3], }, IsPrimary: false, + Enabled: true, }, }, want: nil, @@ -536,6 +549,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, routes: types.Routes{ types.Route{ @@ -547,6 +561,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[0], }, IsPrimary: true, + Enabled: true, }, // Offline types.Route{ @@ -558,6 +573,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[3], }, IsPrimary: false, + Enabled: true, }, types.Route{ Model: gorm.Model{ @@ -568,6 +584,7 @@ func TestFailoverRoute(t *testing.T) { MachineKey: machineKeys[1], }, IsPrimary: true, + Enabled: true, }, }, want: []key.MachinePublic{ @@ -576,6 +593,47 @@ func TestFailoverRoute(t *testing.T) { }, wantErr: false, }, + { + name: "failover-primary-none-enabled", + failingRoute: types.Route{ + Model: gorm.Model{ + ID: 1, + }, + Prefix: ipp("10.0.0.0/24"), + Node: types.Node{ + MachineKey: machineKeys[0], + }, + IsPrimary: true, + Enabled: true, + }, + routes: types.Routes{ + types.Route{ + Model: gorm.Model{ + ID: 1, + }, + Prefix: ipp("10.0.0.0/24"), + Node: types.Node{ + MachineKey: machineKeys[0], + }, + IsPrimary: true, + Enabled: true, + }, + // not enabled + types.Route{ + Model: gorm.Model{ + ID: 2, + }, + Prefix: ipp("10.0.0.0/24"), + Node: types.Node{ + MachineKey: machineKeys[1], + }, + IsPrimary: false, + Enabled: false, + }, + }, + want: nil, + wantErr: false, + }, } for _, tt := range tests {