diff --git a/internal/api/firewall/destination_nat_rules.go b/internal/api/firewall/destination_nat_rules.go index ab927b0..f82a20a 100644 --- a/internal/api/firewall/destination_nat_rules.go +++ b/internal/api/firewall/destination_nat_rules.go @@ -51,7 +51,7 @@ type MoveDestinationNATRuleParameters struct { ToIndex uint64 `json:"to_index"` } -func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params DeleteDestinationNATRuleParameters) (struct{}, error) { +func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params MoveDestinationNATRuleParameters) (struct{}, error) { if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.DestinationNATRules) { return struct{}{}, fmt.Errorf("DestinationNATRule does not Exist") } @@ -59,7 +59,13 @@ func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params DeleteDest t, conf := f.ConfigManager.StartTransaction() defer t.Discard() - conf.Firewall.DestinationNATRules = append(conf.Firewall.DestinationNATRules[:params.Index], conf.Firewall.DestinationNATRules[params.Index+1:]...) + rule := conf.Firewall.DestinationNATRules[params.Index] + sliceWithoutRule := append(conf.Firewall.DestinationNATRules[:params.Index], conf.Firewall.DestinationNATRules[params.Index+1:]...) + newSlice := make([]definitions.DestinationNATRule, params.ToIndex+1) + copy(newSlice, sliceWithoutRule[:params.ToIndex]) + newSlice[params.ToIndex] = rule + conf.Firewall.DestinationNATRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...) + return struct{}{}, t.Commit() } diff --git a/internal/api/firewall/forward_rules.go b/internal/api/firewall/forward_rules.go index f03b894..b1895a8 100644 --- a/internal/api/firewall/forward_rules.go +++ b/internal/api/firewall/forward_rules.go @@ -51,7 +51,7 @@ type MoveForwardRuleParameters struct { ToIndex uint64 `json:"to_index"` } -func (f *Firewall) MoveForwardRule(ctx context.Context, params DeleteForwardRuleParameters) (struct{}, error) { +func (f *Firewall) MoveForwardRule(ctx context.Context, params MoveForwardRuleParameters) (struct{}, error) { if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.ForwardRules) { return struct{}{}, fmt.Errorf("ForwardRule does not Exist") } @@ -59,7 +59,13 @@ func (f *Firewall) MoveForwardRule(ctx context.Context, params DeleteForwardRule t, conf := f.ConfigManager.StartTransaction() defer t.Discard() - conf.Firewall.ForwardRules = append(conf.Firewall.ForwardRules[:params.Index], conf.Firewall.ForwardRules[params.Index+1:]...) + rule := conf.Firewall.ForwardRules[params.Index] + sliceWithoutRule := append(conf.Firewall.ForwardRules[:params.Index], conf.Firewall.ForwardRules[params.Index+1:]...) + newSlice := make([]definitions.ForwardRule, params.ToIndex+1) + copy(newSlice, sliceWithoutRule[:params.ToIndex]) + newSlice[params.ToIndex] = rule + conf.Firewall.ForwardRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...) + return struct{}{}, t.Commit() } diff --git a/internal/api/firewall/source_nat_rules.go b/internal/api/firewall/source_nat_rules.go index 56331d2..6abe25a 100644 --- a/internal/api/firewall/source_nat_rules.go +++ b/internal/api/firewall/source_nat_rules.go @@ -51,7 +51,7 @@ type MoveSourceNATRuleParameters struct { ToIndex uint64 `json:"to_index"` } -func (f *Firewall) MoveSourceNATRule(ctx context.Context, params DeleteSourceNATRuleParameters) (struct{}, error) { +func (f *Firewall) MoveSourceNATRule(ctx context.Context, params MoveSourceNATRuleParameters) (struct{}, error) { if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.SourceNATRules) { return struct{}{}, fmt.Errorf("SourceNATRule does not Exist") } @@ -59,7 +59,13 @@ func (f *Firewall) MoveSourceNATRule(ctx context.Context, params DeleteSourceNAT t, conf := f.ConfigManager.StartTransaction() defer t.Discard() - conf.Firewall.SourceNATRules = append(conf.Firewall.SourceNATRules[:params.Index], conf.Firewall.SourceNATRules[params.Index+1:]...) + rule := conf.Firewall.SourceNATRules[params.Index] + sliceWithoutRule := append(conf.Firewall.SourceNATRules[:params.Index], conf.Firewall.SourceNATRules[params.Index+1:]...) + newSlice := make([]definitions.SourceNATRule, params.ToIndex+1) + copy(newSlice, sliceWithoutRule[:params.ToIndex]) + newSlice[params.ToIndex] = rule + conf.Firewall.SourceNATRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...) + return struct{}{}, t.Commit() }