From b91c19bcb53e61554734062258e939a814d4ec70 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Mon, 10 Feb 2020 18:43:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dgcp=E5=87=BA=E6=96=B9?= =?UTF-8?q?=E5=90=91=E8=A7=84=E5=88=99=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/multicloud/google/securitygroup.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/multicloud/google/securitygroup.go b/pkg/multicloud/google/securitygroup.go index 0796518575..4baa6c3898 100644 --- a/pkg/multicloud/google/securitygroup.go +++ b/pkg/multicloud/google/securitygroup.go @@ -49,6 +49,7 @@ type SFirewall struct { Network string Priority int SourceRanges []string + DestinationRanges []string TargetServiceAccounts []string TargetTags []string Allowed []SFirewallAction @@ -122,12 +123,16 @@ func (firewall *SFirewall) _toRules(action secrules.TSecurityRuleAction) ([]secr default: return nil, fmt.Errorf("unsupport protocol %s", allow.IPProtocol) } - for _, sourceRange := range firewall.SourceRanges { - if regutils.MatchCIDR(sourceRange) { - _, rule.IPNet, _ = net.ParseCIDR(sourceRange) + ipRanges := firewall.SourceRanges + if rule.Direction == secrules.DIR_OUT { + ipRanges = firewall.DestinationRanges + } + for _, ipRange := range ipRanges { + if regutils.MatchCIDR(ipRange) { + _, rule.IPNet, _ = net.ParseCIDR(ipRange) } else { rule.IPNet = &net.IPNet{ - IP: net.ParseIP(sourceRange), + IP: net.ParseIP(ipRange), Mask: net.CIDRMask(32, 32), } }