"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "go/pkg/pass2/spoc2.go" between
Netspoc-6.025.tar.gz and Netspoc-6.026.tar.gz

About: NetSPoC is a network security policy compiler (using its own description language) to manage all the packet filter devices inside your network topology.

spoc2.go  (Netspoc-6.025):spoc2.go  (Netspoc-6.026)
skipping to change at line 34 skipping to change at line 34
*/ */
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/hknutzen/Netspoc/go/pkg/conf" "github.com/hknutzen/Netspoc/go/pkg/conf"
"github.com/hknutzen/Netspoc/go/pkg/diag" "github.com/hknutzen/Netspoc/go/pkg/diag"
"github.com/hknutzen/Netspoc/go/pkg/fileop" "github.com/hknutzen/Netspoc/go/pkg/fileop"
"github.com/hknutzen/Netspoc/go/pkg/info"
"github.com/hknutzen/Netspoc/go/pkg/jcode" "github.com/hknutzen/Netspoc/go/pkg/jcode"
"io/ioutil" "io/ioutil"
"net" "net"
"os" "os"
"os/exec" "os/exec"
"path"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
) )
func panicf(format string, args ...interface{}) { func panicf(format string, args ...interface{}) {
panic(fmt.Sprintf(format, args...)) panic(fmt.Sprintf(format, args...))
} }
type ipNet struct { type ipNet struct {
skipping to change at line 460 skipping to change at line 462
c <- reuse c <- reuse
return return
} }
file := dir + "/" + devicePath file := dir + "/" + devicePath
routerData := prepareACLs(file + ".rules") routerData := prepareACLs(file + ".rules")
config := readFileLines(file + ".config") config := readFileLines(file + ".config")
printCombined(config, routerData, file) printCombined(config, routerData, file)
c <- ok c <- ok
} }
func applyConcurrent(deviceNamesFh *os.File, dir, prev string) { func applyConcurrent(
devices chan string, finished chan bool, dir, prev string) {
var started, generated, reused int var started, generated, reused int
concurrent := conf.Conf.ConcurrencyPass2 concurrent := conf.Conf.ConcurrencyPass2
c := make(chan pass2Result, concurrent) c := make(chan pass2Result, concurrent)
workersLeft := concurrent workersLeft := concurrent
waitAndCheck := func() { waitAndCheck := func() {
switch <-c { switch <-c {
case ok: case ok:
generated++ generated++
case reuse: case reuse:
reused++ reused++
} }
started-- started--
} }
// Read to be processed files line by line. // Read to be processed files line by line.
pass1OK := false for devicePath := range devices {
scanner := bufio.NewScanner(deviceNamesFh)
for scanner.Scan() {
devicePath := scanner.Text()
if devicePath == "." {
pass1OK = true
break
}
if 1 >= concurrent { if 1 >= concurrent {
// Process sequentially. // Process sequentially.
pass2File(devicePath, dir, prev, c) pass2File(devicePath, dir, prev, c)
waitAndCheck() waitAndCheck()
} else if workersLeft > 0 { } else if workersLeft > 0 {
// Start concurrent jobs at beginning. // Start concurrent jobs at beginning.
go pass2File(devicePath, dir, prev, c) go pass2File(devicePath, dir, prev, c)
workersLeft-- workersLeft--
started++ started++
} else { } else {
skipping to change at line 509 skipping to change at line 504
go pass2File(devicePath, dir, prev, c) go pass2File(devicePath, dir, prev, c)
started++ started++
} }
} }
// Wait for all jobs to be finished. // Wait for all jobs to be finished.
for started > 0 { for started > 0 {
waitAndCheck() waitAndCheck()
} }
if err := scanner.Err(); err != nil {
panicf("While reading device names: %v", err)
}
if generated > 0 { if generated > 0 {
diag.Info("Generated files for %d devices", generated) info.Msg("Generated files for %d devices", generated)
} }
if reused > 0 { if reused > 0 {
diag.Info("Reused %d files from previous run", reused) info.Msg("Reused %d files from previous run", reused)
}
if pass1OK {
diag.Progress("Finished")
} }
finished <- true
} }
func Spoc2Main() { func Compile(dir string, fromPass1 chan string, finished chan bool) {
_, dir, abort := conf.GetArgs() prev := path.Join(dir, ".prev")
if dir == "" || abort { applyConcurrent(fromPass1, finished, dir, prev)
return
}
prev := dir + "/.prev"
// Read to be processed files either from STDIN or from file.
var fromPass1 *os.File
if conf.Conf.Pipe {
fromPass1 = os.Stdin
} else {
devlist := dir + "/.devlist"
var err error
fromPass1, err = os.Open(devlist)
if err != nil {
panic(err)
}
}
applyConcurrent(fromPass1, dir, prev)
// Remove directory '.prev' created by pass1 // Remove directory '.prev' created by pass1
// or remove symlink '.prev' created by newpolicy.pl. // or remove symlink '.prev' created by newpolicy.pl.
err := os.RemoveAll(prev) err := os.RemoveAll(prev)
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
 End of changes. 9 change blocks. 
40 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)