Skip to content

Commit

Permalink
CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiriMoran committed Jan 9, 2024
1 parent 74ba11a commit d4bf76f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
9 changes: 9 additions & 0 deletions pkg/common/genericSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ func (s GenericSet[T]) IsIntersect(s2 GenericSet[T]) bool {
}
return false
}

func Contains(s []int, e int) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
19 changes: 3 additions & 16 deletions pkg/ibmvpc/sg_analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,8 @@ func (sga *SGAnalyzer) rulesInConnectivity(target string, conn *common.Connectio
analyzedConns, ipb := sga.getAnalyzedConnsIPB(target, isIngress)
for definedTarget, rules := range analyzedConns.contribRules {
if ipb.ContainedIn(definedTarget) {
definedTargetConn := analyzedConns.allowedconns[definedTarget]
if conn != nil { // connection not part of the query
definedTargetConn := analyzedConns.allowedconns[definedTarget]
contained, err := conn.ContainedIn(definedTargetConn)
contained, err := conn.ContainedIn(analyzedConns.allowedconns[definedTarget])
if err != nil {
return nil, err
}
Expand All @@ -348,25 +346,14 @@ func (sga *SGAnalyzer) rulesInConnectivity(target string, conn *common.Connectio
// given a list of rules and a connection, return the sublist of rules that contributes to the connection
func (sga *SGAnalyzer) getRulesRelevantConn(rules []int, conn *common.ConnectionSet) ([]int, error) {
relevantRules := []int{}
allRules := sga.ingressRules
allRules = append(allRules, sga.egressRules...)
for _, rule := range allRules {
if contains(rules, rule.index) && !conn.Intersection(rule.connections).IsEmpty() {
for _, rule := range append(sga.ingressRules, sga.egressRules...) {
if common.Contains(rules, rule.index) && !conn.Intersection(rule.connections).IsEmpty() {
relevantRules = append(relevantRules, rule.index)
}
}
return relevantRules, nil
}

func contains(s []int, e int) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

func (sga *SGAnalyzer) getAnalyzedConnsIPB(target string, isIngress bool) (res *ConnectivityResult, ipb *common.IPBlock) {
ipb = common.NewIPBlockFromCidrOrAddress(target)
if isIngress {
Expand Down

0 comments on commit d4bf76f

Please sign in to comment.