From 9cbcf7531fd4c3e2a4238e7b700e8719bcec2b63 Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Mon, 24 Mar 2025 00:56:51 +0100 Subject: [PATCH] [management] Fix invalid port range sync (#3571) We should not send port range when a port is set or when protocol is all or icmp --- management/server/policy.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/management/server/policy.go b/management/server/policy.go index bbc85f6ae..d222bba8a 100644 --- a/management/server/policy.go +++ b/management/server/policy.go @@ -255,15 +255,24 @@ func toProtocolFirewallRules(rules []*types.FirewallRule) []*proto.FirewallRule for i := range rules { rule := rules[i] - result[i] = &proto.FirewallRule{ + fwRule := &proto.FirewallRule{ PolicyID: []byte(rule.PolicyID), PeerIP: rule.PeerIP, Direction: getProtoDirection(rule.Direction), Action: getProtoAction(rule.Action), Protocol: getProtoProtocol(rule.Protocol), Port: rule.Port, - PortInfo: rule.PortRange.ToProto(), } + + if shouldUsePortRange(fwRule) { + fwRule.PortInfo = rule.PortRange.ToProto() + } + + result[i] = fwRule } return result } + +func shouldUsePortRange(rule *proto.FirewallRule) bool { + return rule.Port == "" && (rule.Protocol == proto.RuleProtocol_UDP || rule.Protocol == proto.RuleProtocol_TCP) +}