From 78bd1ddf0633e30127a163b42ac8175ea2a106cd Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Sat, 23 Nov 2024 11:42:14 +0100 Subject: [PATCH] split function --- management/server/route.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/management/server/route.go b/management/server/route.go index 5310bcd1cd1..dc76ea0c093 100644 --- a/management/server/route.go +++ b/management/server/route.go @@ -421,25 +421,32 @@ func (a *Account) getPeerRoutesFirewallRules(ctx context.Context, peerID string, for _, accessGroup := range route.AccessControlGroups { policies := getAllRoutePoliciesFromGroups(a, []string{accessGroup}) - for _, policy := range policies { - if !policy.Enabled { - continue - } + rules := a.getRouteFirewallRules(ctx, peerID, policies, route, validatedPeersMap, distributionPeers) + routesFirewallRules = append(routesFirewallRules, rules...) + } + } - for _, rule := range policy.Rules { - if !rule.Enabled { - continue - } + return routesFirewallRules +} - rulePeers := a.getRulePeers(rule, peerID, distributionPeers, validatedPeersMap) - rules := generateRouteFirewallRules(ctx, route, rule, rulePeers, firewallRuleDirectionIN) - routesFirewallRules = append(routesFirewallRules, rules...) - } +func (a *Account) getRouteFirewallRules(ctx context.Context, peerID string, policies []*Policy, route *route.Route, validatedPeersMap map[string]struct{}, distributionPeers map[string]struct{}) []*RouteFirewallRule { + fwRules := make([]*RouteFirewallRule, 0) + for _, policy := range policies { + if !policy.Enabled { + continue + } + + for _, rule := range policy.Rules { + if !rule.Enabled { + continue } + + rulePeers := a.getRulePeers(rule, peerID, distributionPeers, validatedPeersMap) + rules := generateRouteFirewallRules(ctx, route, rule, rulePeers, firewallRuleDirectionIN) + fwRules = append(fwRules, rules...) } } - - return routesFirewallRules + return fwRules } func (a *Account) getRulePeers(rule *PolicyRule, peerID string, distributionPeers map[string]struct{}, validatedPeersMap map[string]struct{}) []*nbpeer.Peer {