Skip to content

Commit

Permalink
No raw/ipv6, all raw config is put into raw/
Browse files Browse the repository at this point in the history
  • Loading branch information
hknutzen committed Aug 29, 2023
1 parent db76956 commit 3200986
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 131 deletions.
35 changes: 7 additions & 28 deletions go/pkg/pass1/copy-raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/hknutzen/Netspoc/go/pkg/fileop"
"github.com/hknutzen/Netspoc/go/pkg/filetree"
)

// 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.
Expand All @@ -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)
Expand All @@ -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, "")
}
}
}
24 changes: 0 additions & 24 deletions go/testdata/ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 1 addition & 1 deletion go/testdata/ipv6/convert.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand Down
63 changes: 63 additions & 0 deletions go/testdata/ipv6/nat_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go/testdata/ipv6/raw_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 0 additions & 1 deletion go/testdata/ipv6/reuse-previous_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ cat <<END > old/r1.info
{"generated_by":"devel","model":"ASA","name_list":["r1"]}
END
cat <<END > old/r1.config
END
cat <<END > old/r1.rules
{"model":"ASA","acls":null,"do_objectgroup":true}
Expand Down
76 changes: 0 additions & 76 deletions go/testdata/mixed-ipv4-ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3200986

Please sign in to comment.