diff --git a/go/pkg/pass1/copy-raw.go b/go/pkg/pass1/copy-raw.go index cc6e85e7..3cbb5571 100644 --- a/go/pkg/pass1/copy-raw.go +++ b/go/pkg/pass1/copy-raw.go @@ -4,7 +4,6 @@ import ( "os" "os/exec" "path/filepath" - "strings" "github.com/hknutzen/Netspoc/go/pkg/fileop" "github.com/hknutzen/Netspoc/go/pkg/filetree" @@ -12,13 +11,14 @@ import ( // Copy raw configuration files of devices into outDir for devices // known from topology. -func (c *spoc) copyRaw1(rawDir, outDir, ignoreDir string) { - ipV6 := strings.HasSuffix(outDir, "/ipv6") +func (c *spoc) copyRaw(inPath, outDir string) { + rawDir := filepath.Join(inPath, "raw") + if !fileop.IsDir(rawDir) { + return + } deviceNames := make(map[string]bool) for _, r := range c.managedRouters { - if r.ipV6 == ipV6 { - deviceNames[r.deviceName] = true - } + deviceNames[r.deviceName] = true } // outDir has already been checked / created in printCode. @@ -28,7 +28,7 @@ func (c *spoc) copyRaw1(rawDir, outDir, ignoreDir string) { } for _, file := range files { base := file.Name() - if base[0] == '.' || base == filetree.Ignore || base == ignoreDir { + if base[0] == '.' || base == filetree.Ignore { continue } rawPath := filepath.Join(rawDir, base) @@ -48,24 +48,3 @@ func (c *spoc) copyRaw1(rawDir, outDir, ignoreDir string) { } } } - -func (c *spoc) copyRaw(inPath, outDir string) { - rawDir := filepath.Join(inPath, "raw") - if !fileop.IsDir(rawDir) { - return - } - outV6 := filepath.Join(outDir, "ipv6") - if c.conf.IPV6 { - c.copyRaw1(rawDir, outV6, "ipv4") - subDir := filepath.Join(rawDir, "ipv4") - if fileop.IsDir(subDir) { - c.copyRaw1(subDir, outDir, "") - } - } else { - c.copyRaw1(rawDir, outDir, "ipv6") - subDir := filepath.Join(rawDir, "ipv6") - if fileop.IsDir(subDir) { - c.copyRaw1(subDir, outV6, "") - } - } -} diff --git a/go/testdata/ipv6.t b/go/testdata/ipv6.t index 41994567..4ef9c057 100644 --- a/go/testdata/ipv6.t +++ b/go/testdata/ipv6.t @@ -491,27 +491,3 @@ router:r1 = { Error: Can't mkdir out/ipv6: file exists Aborted =OPTIONS=--ipv6 - -############################################################ -=TITLE=Can't copy raw file -=SETUP= -mkdir -p out/.prev -mkdir -p out/ipv6/r1.raw/r1 -=PARAMS=--ipv6 -=INPUT= ---topo -network:n1 = { ip = ::a01:100/120; } -router:r1 = { - model = IOS; - managed; - interface:n1 = { ip = ::a01:101; hardware = n1; } -} ---raw/r1 -ipv6 route ::a01:200/120 ::a01:101 -=WITH_OUTDIR= -=ERROR= -Error: Can't cp raw/r1 to out/ipv6/r1.raw: exit status 1 -cp: cannot overwrite directory 'out/ipv6/r1.raw/r1' with non-directory - -Aborted -=END= diff --git a/go/testdata/ipv6/convert.pl b/go/testdata/ipv6/convert.pl index 770af8b8..338bcbd2 100644 --- a/go/testdata/ipv6/convert.pl +++ b/go/testdata/ipv6/convert.pl @@ -245,7 +245,7 @@ sub adjust_testfile { # Change path of to be checked output files. # IPv6 files are generated in ipv6/ subdirectory. - if ($line !~ m(topology|config|file|raw/| raw$|private) and + if ($line !~ m(topology|config|file|raw/|[.]raw$| raw$|private) and $filename !~ /export.t/) { $line =~ s/^(-+[ ]*)([^\s>-]+)([ ]*)$/${1}ipv6\/$2$3/; diff --git a/go/testdata/ipv6/nat_ipv6.t b/go/testdata/ipv6/nat_ipv6.t index 701d9c4f..46f3de73 100644 --- a/go/testdata/ipv6/nat_ipv6.t +++ b/go/testdata/ipv6/nat_ipv6.t @@ -720,6 +720,69 @@ Warning: Ignoring useless nat:h bound at interface:r2.n3 Warning: Ignoring useless nat:h bound at interface:r3.n3 =END= +############################################################ +=TITLE=Bound to same interfaces +=PARAMS=--ipv6 +=INPUT= +network:n1 = { ip = ::a01:100/120; nat:n1 = { ip = ::a09:100/120; } } +network:n2 = { ip = ::a01:200/120; nat:n2 = { ip = ::a09:200/120; } } +network:n3 = { ip = ::a01:300/120; nat:n3 = { ip = ::a09:300/125; dynamic; }} +network:n4 = { ip = ::a01:400/120; } +network:n5 = { ip = ::a01:500/120; } +router:r1 = { + interface:n1; + interface:n2; + interface:n3; + interface:n4 = { bind_nat = n1, n2, n3; } + interface:n5 = { bind_nat = n1, n2, n3; } +} +=WARNING= +Warning: nat:n1 and nat:n2 are bound to same interfaces + and should be merged into a single definition +Warning: nat:n1 and nat:n3 are bound to same interfaces + and should be merged into a single definition +Warning: nat:n2 and nat:n3 are bound to same interfaces + and should be merged into a single definition +=END= + +############################################################ +=TITLE=Bound to same and different interfaces +=PARAMS=--ipv6 +=INPUT= +network:n1 = { ip = ::a01:100/120; nat:n1 = { ip = ::a09:100/120; } } +network:n2 = { ip = ::a01:200/120; nat:n2 = { ip = ::a09:200/120; } } +network:n3 = { ip = ::a01:300/120; nat:n3 = { ip = ::a09:300/125; dynamic; }} +network:n4 = { ip = ::a01:400/120; } +network:n5 = { ip = ::a01:500/120; } +network:n6 = { ip = ::a01:600/120; } +router:r1 = { + interface:n1; + interface:n2; + interface:n3; + interface:n4 = { bind_nat = n1, n2; } + interface:n5 = { bind_nat = n2, n3; } + interface:n6 = { bind_nat = n1, n3; } +} +=WARNING=NONE + +############################################################ +=TITLE=Bound to same interfaces, but one is hidden +=PARAMS=--ipv6 +=INPUT= +network:n1 = { ip = ::a01:100/120; nat:n1 = { hidden; } } +network:n2 = { ip = ::a01:200/120; nat:n2 = { ip = ::a09:200/120; } } +network:n3 = { ip = ::a01:300/120; nat:n3 = { ip = ::a09:300/125; dynamic; }} +network:n4 = { ip = ::a01:400/120; } +network:n5 = { ip = ::a01:500/120; } +router:r1 = { + interface:n1; + interface:n2; + interface:n3; + interface:n4 = { bind_nat = n1, n2; } + interface:n5 = { bind_nat = n1, n3; } +} +=WARNING=NONE + ############################################################ =TITLE=Non matching static NAT mask =PARAMS=--ipv6 diff --git a/go/testdata/ipv6/raw_ipv6.t b/go/testdata/ipv6/raw_ipv6.t index ad3c9306..3413de04 100644 --- a/go/testdata/ipv6/raw_ipv6.t +++ b/go/testdata/ipv6/raw_ipv6.t @@ -33,7 +33,7 @@ ipv6 route ::a01:200/120 ::a01:101 Warning: Ignoring path raw/aaa Warning: Found unused file raw/r0 =OUTPUT= ---ipv6/r1.raw +--r1.raw ! manual route ipv6 route ::a01:200/120 ::a01:101 =END= diff --git a/go/testdata/ipv6/reuse-previous_ipv6.t b/go/testdata/ipv6/reuse-previous_ipv6.t index 740e863f..6e8898f2 100644 --- a/go/testdata/ipv6/reuse-previous_ipv6.t +++ b/go/testdata/ipv6/reuse-previous_ipv6.t @@ -137,7 +137,6 @@ cat < old/r1.info {"generated_by":"devel","model":"ASA","name_list":["r1"]} END cat < old/r1.config - END cat < old/r1.rules {"model":"ASA","acls":null,"do_objectgroup":true} diff --git a/go/testdata/mixed-ipv4-ipv6.t b/go/testdata/mixed-ipv4-ipv6.t index 03a02db6..9f50c213 100644 --- a/go/testdata/mixed-ipv4-ipv6.t +++ b/go/testdata/mixed-ipv4-ipv6.t @@ -247,82 +247,6 @@ Error: topology seems to be empty Aborted =OPTIONS=--ipv6 -############################################################ -=TITLE=Raw files for IPv4 and IPv6 -=TEMPL=input --- ipv4 -network:n1 = { ip = 10.1.1.0/24; } -router:r1 = { - managed; - model = ASA; - interface:n1 = { ip = 10.1.1.1; hardware = n1; } -} --- {{.v4}} -access-list n1_in extended permit icmp any4 any4 -access-group n1_in in interface n1 --- ipv6/topo -network:n3 = { ip = 1000::abcd:0001:0/112;} -router:r1 = { - managed; - model = ASA; - interface:n3 = {ip = 1000::abcd:0001:0001; hardware = n1;} -} --- {{.v6}} -access-list n1_in extended permit icmp6 any6 any6 -access-group n1_in in interface n1 -=INPUT=[[input {v4: raw/r1, v6: raw/ipv6/r1}]] -=TEMPL=output ---r1 -! n1_in -access-list n1_in extended deny ip any4 any4 -access-group n1_in in interface n1 ---r1.raw -access-list n1_in extended permit icmp any4 any4 -access-group n1_in in interface n1 ---ipv6/r1 -! n1_in -access-list n1_in extended deny ip any6 any6 -access-group n1_in in interface n1 ---ipv6/r1.raw -access-list n1_in extended permit icmp6 any6 any6 -access-group n1_in in interface n1 -=OUTPUT= -[[output]] -=END= - -############################################################ -=TITLE=Raw files for IPv6 and IPv4 -=INPUT=[[input {v4: raw/ipv4/r1, v6: raw/r1}]] -=OPTIONS=--ipv6 -=OUTPUT= -[[output]] -=END= - -############################################################ -=TITLE=Invalid file and directory in raw/ipv6 -=INPUT= --- ipv4 -network:n1 = { ip = 10.1.1.0/24; } -router:r1 = { - managed; - model = ASA; - interface:n1 = { ip = 10.1.1.1; hardware = n1; } -} --- raw/ipv6/r1 -access-list n1_in extended permit icmp6 any6 any6 -access-group n1_in in interface n1 --- raw/ipv6/ipv6/foo -foo -=WARNING= -Warning: Ignoring path raw/ipv6/ipv6 -Warning: Found unused file raw/ipv6/r1 -=OUTPUT= ---r1 -! n1_in -access-list n1_in extended deny ip any4 any4 -access-group n1_in in interface n1 -=END= - ############################################################ =TITLE=Verbose output with progress messages =TEMPL=input