Skip to content

Commit

Permalink
Perl->Go: NormalizeServices, expandGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
hknutzen committed Jan 10, 2020
1 parent 02d4526 commit df512cf
Show file tree
Hide file tree
Showing 26 changed files with 2,034 additions and 200 deletions.
7 changes: 4 additions & 3 deletions go/cmd/spoc1-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"github.com/hknutzen/Netspoc/go/pkg/diag"
"github.com/hknutzen/Netspoc/go/pkg/pass1"
"os"
)

func main() {
pass1.ImportFromPerl()
initialErrors := pass1.ErrorCounter

pass1.NormalizeServices()
pass1.AbortOnError()

pass1.CheckServiceOwner()
pRules, dRules := pass1.ConvertHostsInRules()
Expand All @@ -33,6 +34,6 @@ func main() {
pass1.PrintCode(pass1.OutDir)
pass1.CopyRaw(pass1.InPath, pass1.OutDir)
}
pass1.AbortOnError()
diag.Progress("Finished pass1")
os.Exit(pass1.ErrorCounter - initialErrors)
}
Binary file modified go/cmd/spoc1-go/spoc1-go
Binary file not shown.
2 changes: 1 addition & 1 deletion go/pkg/pass1/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func getHostMask(ip net.IP, ipv6 bool) net.IPMask {
return net.CIDRMask(32, 32)
}

var zeroIP = net.ParseIP("0.0.0.0")
var zeroIP = net.ParseIP("0.0.0.0").To4()
var zeroIPv6 = net.ParseIP("::")

func getZeroIp(ipv6 bool) net.IP {
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/pass1/check-redundant.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func getOrigPrt(rule *expandedRule) *proto {
# Expand rules and check them for redundancy
########################################################################*/

// Derive reduced 'local_up' relation from 'up' relation between protocols.
// Derive reduced 'localUp' relation from 'up' relation between protocols.
// Reduced relation has only protocols that are referenced in list of rules.
// New relation is used in findRedundantRules.
// We get better performance compared to original relation, because
Expand Down
15 changes: 9 additions & 6 deletions go/pkg/pass1/check-service-owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,23 @@ func CheckServiceOwner() {
// if objects of user and objects of rules are swapped.
var userOwner *owner
simpleUser := true
for _, user := range svc.user {
owner := user.getOwner()
if owner == nil {
for _, user := range svc.expandedUser {
var o *owner
if obj, ok := user.(srvObj); ok {
o = obj.getOwner()
}
if o == nil {
simpleUser = false
break
}
if userOwner == nil {
userOwner = owner
} else if userOwner != owner {
userOwner = o
} else if userOwner != o {
simpleUser = false
break
}
}
if simpleUser {
if simpleUser && userOwner != nil {
warnMsg("Useless use of attribute 'multi_owner' at %s\n"+
" All 'user' objects belong to single %s.\n"+
" Either swap objects of 'user' and objects of rules,\n"+
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/pass1/check-supernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func findZoneNetworks(zone *zone, ip net.IP, mask net.IPMask, natSet natSet, net
}
}
}
key := string(ip) + string(mask)
key := ipmask{string(ip), string(mask)}
aggregate := zone.ipmask2aggregate[key]
if aggregate != nil && !aggregate.invisible {
if inNetHash(aggregate) {
Expand Down Expand Up @@ -134,7 +134,7 @@ func findZoneNetworks(zone *zone, ip net.IP, mask net.IPMask, natSet natSet, net
}
}
if zone.ipmask2net == nil {
zone.ipmask2net = make(map[string]netList)
zone.ipmask2net = make(map[ipmask]netList)
}
zone.ipmask2net[key] = result
return result
Expand Down
8 changes: 4 additions & 4 deletions go/pkg/pass1/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func debug(format string, args ...interface{}) {
func checkAbort() {
ErrorCounter++
if ErrorCounter >= conf.Conf.MaxErrors {
fmt.Fprintf(os.Stderr, "Aborted after %d errors\n", ErrorCounter)
// fmt.Fprintf(os.Stderr, "Aborted after %d errors\n", ErrorCounter)
os.Exit(ErrorCounter)
}
}

func abortOnError() {
func AbortOnError() {
if ErrorCounter > 0 {
fmt.Fprintf(os.Stderr, "Aborted with %d errors\n", ErrorCounter)
// fmt.Fprintf(os.Stderr, "Aborted with %d error(s)\n", ErrorCounter)
os.Exit(ErrorCounter)
}
}
Expand All @@ -40,7 +40,7 @@ func errMsg(format string, args ...interface{}) {
}

func internalErr(format string, args ...interface{}) {
abortOnError()
AbortOnError()
string := "Internal error: " + fmt.Sprintf(format, args...)
fmt.Fprintln(os.Stderr, string)
checkAbort()
Expand Down
Loading

0 comments on commit df512cf

Please sign in to comment.