Skip to content

Commit

Permalink
Removed support for separate IPv6 topology
Browse files Browse the repository at this point in the history
  • Loading branch information
hknutzen committed Jan 24, 2025
1 parent c87367f commit 497b175
Show file tree
Hide file tree
Showing 112 changed files with 6,843 additions and 13,120 deletions.
12 changes: 11 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
{{$NEXT}}

- Fixed duplicate hosts from wrong IPv4 network in IPv6 aggregate.
- Removed support for separate IPv6 topology in subdirectory 'ipv6/'.
- Removed options '--ipv6', '-6'.
- Removed support for NAT of IPv6 objects.
After changing attributes of IPv6 addresses from 'ip' to 'ip6',
supporting NAT for IPv6 would need to change NAT attributes
to 'ip6', 'hidden6', 'identity6' as well.
This seems to be superflous, since nobody uses NAT for IPv6.
- Fixed duplicate hosts in print-group from wrong IPv4 network
in IPv6 aggregate.
- Fixed panic in export-netspoc with rule from IPv4 network to
combined IPv4/v6 auto interface.
- Changed 'format-netspoc' to print attributes "ip" and "ip6" in
one line, if object has no more than 3 attributes.

6.076 2025-01-10 09:39:54+01:00 Europe/Berlin

Expand Down
2 changes: 1 addition & 1 deletion go/pkg/addto/add-to-netspoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func Main(d oslink.Data) int {
dummyArgs := []string{fmt.Sprintf("--quiet=%v", *quiet)}
cnf := conf.ConfigFromArgsAndFile(dummyArgs, path)

s, err := astset.Read(path, cnf.IPV6)
s, err := astset.Read(path)
if err != nil {
fmt.Fprintf(d.Stderr, "Error: %s\n", err)
return 1
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/api/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Main(d oslink.Data) int {

s := new(state)
var err error
s.State, err = astset.Read(netspocPath, cnf.IPV6)
s.State, err = astset.Read(netspocPath)
if err != nil {
// Text of this error message is checked in git-worker1 of Netspoc-API.
showErr("While reading netspoc files: %s", err)
Expand Down
39 changes: 7 additions & 32 deletions go/pkg/api/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func (s *state) patch(j *job) error {
Path string
Value interface{}
OkIfExists bool `json:"ok_if_exists"`
IPV6 *bool
}
getParams(j, &p)
c := change{val: p.Value, okIfExists: p.OkIfExists}
Expand All @@ -31,19 +30,13 @@ func (s *state) patch(j *job) error {
if len(p.Path) == 0 {
return fmt.Errorf("Invalid empty path")
}
var ipv6 bool
if p.IPV6 != nil {
ipv6 = *p.IPV6
} else {
ipv6 = s.IPV6
}
path := strings.Split(p.Path, ",")
top, names, err := s.findToplevel(path, ipv6, c)
top, names, err := s.findToplevel(path, c)
if err != nil {
return err
}
if top == nil {
return s.addToplevel(path[0], ipv6, c)
return s.addToplevel(path[0], c)
}
process := func() error {
if len(names) == 0 {
Expand Down Expand Up @@ -99,9 +92,8 @@ func (s *state) patch(j *job) error {
return err
}

func (s *state) findToplevel(names []string, ipv6 bool, c change,
func (s *state) findToplevel(names []string, c change,
) (ast.Toplevel, []string, error) {

topName := names[0]
var top ast.Toplevel
if strings.HasPrefix(topName, "host:") {
Expand Down Expand Up @@ -139,21 +131,15 @@ func (s *state) findToplevel(names []string, ipv6 bool, c change,
}
return top, names, nil
} else {
isRouter := strings.HasPrefix(topName, "router:")
names = names[1:]
s.Modify(func(t ast.Toplevel) bool {
if t.GetName() == topName && (!isRouter || t.GetIPV6() == ipv6) {
if t.GetName() == topName {
top = t
return true // Mark as modified.
}
return false
})
if top == nil && len(names) > 0 {
if isRouter {
ipvx := getIPvX(ipv6)
return nil, nil, fmt.Errorf(
"Can't modify unknown %s '%s'", ipvx, topName)
}
return nil, nil, fmt.Errorf(
"Can't modify unknown toplevel object '%s'", topName)
}
Expand Down Expand Up @@ -389,7 +375,7 @@ func newAttribute(l *[]*ast.Attribute, name string, c change) error {
return nil
}

func (s *state) addToplevel(name string, ipv6 bool, c change) error {
func (s *state) addToplevel(name string, c change) error {
if c.method == "delete" {
return fmt.Errorf("Can't %s unknown toplevel node '%s'", c.method, name)
}
Expand All @@ -398,7 +384,7 @@ func (s *state) addToplevel(name string, ipv6 bool, c change) error {
if err != nil {
return err
}
s.AddTopLevel(a, ipv6)
s.AddTopLevel(a)
return nil
}

Expand Down Expand Up @@ -485,11 +471,7 @@ func (s *state) patchToplevel(n ast.Toplevel, c change) error {
if c.okIfExists {
return nil
}
ipvx := ""
if r, ok := n.(*ast.Router); ok {
ipvx = getIPvX(r.IPV6) + " "
}
return fmt.Errorf("%s'%s' already exists", ipvx, n.GetName())
return fmt.Errorf("'%s' already exists", n.GetName())
}

func getTopList(name string, m map[string]interface{}) (ast.Toplevel, error) {
Expand Down Expand Up @@ -730,10 +712,3 @@ func getElementList(val interface{}) ([]ast.Element, error) {
}
return elements, nil
}

func getIPvX(v6 bool) string {
if v6 {
return "IPv6"
}
return "IPv4"
}
11 changes: 5 additions & 6 deletions go/pkg/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type Toplevel interface {
GetDescription() *Description
FileName() string
SetFileName(string)
GetIPV6() bool
SetIPV6()
}

type ToplevelWithAttr interface {
Expand Down Expand Up @@ -121,7 +119,11 @@ type AggAuto struct {
func (a AggAuto) String() string {
var ext string
if a.Net != "" {
ext = "ip=" + a.Net + "&"
attr := "ip"
if a.IPV6 {
attr += "6"
}
ext = attr + "=" + a.Net + "&"
}
return a.GetType() + ":[" + ext + joinElements(a.Elements, ",") + "]"
}
Expand Down Expand Up @@ -187,16 +189,13 @@ type TopBase struct {
Name string
Description *Description
fileName string
IPV6 bool
}

func (a TopBase) GetName() string { return a.Name }
func (a *TopBase) SetName(n string) { a.Name = n }
func (a TopBase) GetDescription() *Description { return a.Description }
func (a TopBase) FileName() string { return a.fileName }
func (a *TopBase) SetFileName(n string) { a.fileName = n }
func (a TopBase) GetIPV6() bool { return a.IPV6 }
func (a *TopBase) SetIPV6() { a.IPV6 = true }

type TopList struct {
TopBase
Expand Down
17 changes: 4 additions & 13 deletions go/pkg/astset/astset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ type State struct {
astFiles []*ast.File
base string
files []string
IPV6 bool
changed map[string]bool
}

func Read(netspocBase string, v6 bool) (*State, error) {
func Read(netspocBase string) (*State, error) {
s := &State{
base: netspocBase,
IPV6: v6,
changed: make(map[string]bool),
}
err := filetree.Walk(netspocBase, v6, func(input *filetree.Context) error {
err := filetree.Walk(netspocBase, func(input *filetree.Context) error {
source := []byte(input.Data)
path := input.Path
aF, err := parser.ParseFile(source, path, input.IPV6, parser.ParseComments)
aF, err := parser.ParseFile(source, path, parser.ParseComments)
if err != nil {
return err
}
Expand Down Expand Up @@ -128,7 +126,7 @@ func (s *State) FindToplevel(name string) ast.Toplevel {
return result
}

func (s *State) AddTopLevel(n ast.Toplevel, ipv6 bool) {
func (s *State) AddTopLevel(n ast.Toplevel) {
// Netspoc config is given in single file, add new node to this file.
if len(s.files) == 1 && s.files[0] == s.base {
s.CreateToplevel("", n)
Expand All @@ -155,13 +153,6 @@ func (s *State) AddTopLevel(n ast.Toplevel, ipv6 bool) {
file = path.Join(file, "other")
}
}
if ipv6 != s.IPV6 {
if s.IPV6 {
file = path.Join("ipv4", file)
} else {
file = path.Join("ipv6", file)
}
}
s.CreateToplevel(file, n)
}

Expand Down
4 changes: 0 additions & 4 deletions go/pkg/conf/GetArgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type Config struct {
AutoDefaultRoute bool
ConcurrencyPass1 int
ConcurrencyPass2 int
IPV6 bool `flag:"ipv6 6"`
MaxErrors int `flag:"max_errors m"`
Quiet bool `flag:"quiet q"`
TimeStamps bool `flag:"time_stamps t"`
Expand Down Expand Up @@ -148,9 +147,6 @@ func defaultOptions(fs *flag.FlagSet) *Config {
// which have no default route to the internet.
AutoDefaultRoute: true,

// Use IPv4 version as default
IPV6: false,

// Set value to >= 2 to start concurrent processing.
ConcurrencyPass1: 1,
ConcurrencyPass2: 1,
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/expand/expand-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Main(d oslink.Data) int {
// Change files.
s := new(state)
var err error
s.State, err = astset.Read(path, cnf.IPV6)
s.State, err = astset.Read(path)
if err != nil {
fmt.Fprintf(d.Stderr, "Error: %s\n", err)
return 1
Expand Down
9 changes: 2 additions & 7 deletions go/pkg/exportsyntax/export-netspoc-syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/hknutzen/Netspoc/go/pkg/ast"
"github.com/hknutzen/Netspoc/go/pkg/conf"
"github.com/hknutzen/Netspoc/go/pkg/filetree"
"github.com/hknutzen/Netspoc/go/pkg/oslink"
"github.com/hknutzen/Netspoc/go/pkg/parser"
Expand Down Expand Up @@ -41,13 +40,12 @@ func Main(d oslink.Data) int {
filter[name] = true
}
path := args[0]
cnf := conf.ConfigFromArgsAndFile(nil, path)
// Group definitions by type.
definitions := make(map[string][]jsonMap)
err := filetree.Walk(path, cnf.IPV6, func(input *filetree.Context) error {
err := filetree.Walk(path, func(input *filetree.Context) error {
source := []byte(input.Data)
path := input.Path
aF, err := parser.ParseFile(source, path, input.IPV6, 0)
aF, err := parser.ParseFile(source, path, 0)
if err != nil {
return err
}
Expand Down Expand Up @@ -79,9 +77,6 @@ func convertToMap(n ast.Toplevel) jsonMap {
if d := n.GetDescription(); d != nil {
m["description"] = d.Text
}
if v := n.GetIPV6(); v {
m["ipv6"] = v
}
if x, ok := n.(ast.ToplevelWithAttr); ok {
mapAttributes(m, x.GetAttributes())
}
Expand Down
24 changes: 8 additions & 16 deletions go/pkg/filetree/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import (
type Context struct {
Path string
Data string
IPV6 bool
}
type parser func(*Context) error

// Read input from file and process it by function which is given as argument.
func processFile(fname string, v6 bool, fn parser) error {
input := &Context{Path: fname, IPV6: v6}
func processFile(fname string, fn parser) error {
input := &Context{Path: fname}
content, err := os.ReadFile(fname)
if err != nil {
return err
Expand All @@ -26,9 +25,9 @@ func processFile(fname string, v6 bool, fn parser) error {
return fn(input)
}

func Walk(fname string, v6 bool, fn parser) error {
var walk func(string, bool, bool) error
walk = func(fname string, v6, toplevel bool) error {
func Walk(fname string, fn parser) error {
var walk func(string, bool) error
walk = func(fname string, toplevel bool) error {
if !toplevel {
base := path.Base(fname)

Expand All @@ -37,16 +36,9 @@ func Walk(fname string, v6 bool, fn parser) error {
return nil
}

// Handle ipv6 / ipv4 subdirectory or file.
switch base {
case "ipv4":
v6 = false
case "ipv6":
v6 = true
}
}
if !fileop.IsDir(fname) {
return processFile(fname, v6, fn)
return processFile(fname, fn)
}
files, err := os.ReadDir(fname)
if err != nil {
Expand All @@ -60,12 +52,12 @@ func Walk(fname string, v6 bool, fn parser) error {
continue
}
name := filepath.Join(fname, base)
if err := walk(name, v6, false); err != nil {
if err := walk(name, false); err != nil {
return err
}
}
return nil
}
toplevel := true
return walk(fname, v6, toplevel)
return walk(fname, toplevel)
}
4 changes: 2 additions & 2 deletions go/pkg/format/format-netspoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func Main(d oslink.Data) int {
cnf := conf.ConfigFromArgsAndFile(dummyArgs, path)

// Process each file.
err := filetree.Walk(path, cnf.IPV6, func(input *filetree.Context) error {
err := filetree.Walk(path, func(input *filetree.Context) error {
source := []byte(input.Data)
path := input.Path
aF, err := parser.ParseFile(source, path, input.IPV6, parser.ParseComments)
aF, err := parser.ParseFile(source, path, parser.ParseComments)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 497b175

Please sign in to comment.