pathpol

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Pathpol lib

This directory contains the sequence parser. The parser was generated by Antlr and stored in this git repository, in the sequence subdirectory. That way the project doesn't have a build dependency on Antlr tool. However, there's still the dependency on Antlr runtime library.

If sequence grammar (Sequence.g4) is changed the parser has to be regenerated. To do so, install Antlr on your machine, and run make in this directory.

Documentation

Overview

Package pathpol implements path policies, documentation in doc/PathPolicy.md Currently implemented: ACL, Sequence, Extends and Options.

A policy has an Act() method that takes an AppPathSet and returns a filtered AppPathSet

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDefault indicates that there is no default acl entry.
	ErrNoDefault = errors.New("ACL does not have a default")
)

Functions

This section is empty.

Types

type ACL

type ACL struct {
	Entries []*ACLEntry
}

func NewACL

func NewACL(entries ...*ACLEntry) (*ACL, error)

NewACL creates a new entry and checks for the presence of a default action

func (*ACL) Eval

func (a *ACL) Eval(inputSet PathSet) PathSet

Eval returns the set of paths that match the ACL.

func (*ACL) MarshalJSON

func (a *ACL) MarshalJSON() ([]byte, error)

func (*ACL) UnmarshalJSON

func (a *ACL) UnmarshalJSON(b []byte) error

type ACLAction

type ACLAction bool

ACLAction has two options: Deny and Allow

const (
	Deny  ACLAction = false
	Allow ACLAction = true
)

type ACLEntry

type ACLEntry struct {
	Action ACLAction
	Rule   *HopPredicate
}

func (*ACLEntry) LoadFromString

func (ae *ACLEntry) LoadFromString(str string) error

func (*ACLEntry) MarshalJSON

func (ae *ACLEntry) MarshalJSON() ([]byte, error)

func (*ACLEntry) String

func (ae *ACLEntry) String() string

func (*ACLEntry) UnmarshalJSON

func (ae *ACLEntry) UnmarshalJSON(b []byte) error

type ExtPolicy

type ExtPolicy struct {
	Extends []string `json:"extends,omitempty"`
	*Policy
}

ExtPolicy is an extending policy, it may have a list of policies it extends

type FilterOptions

type FilterOptions struct {
	// IgnoreSequence can be used to ignore the sequence part of policies.
	IgnoreSequence bool
}

FilterOptions contains options for filtering.

type HopPredicate

type HopPredicate struct {
	ISD   addr.ISD
	AS    addr.AS
	IfIDs []common.IFIDType
}

A HopPredicate specifies a hop in the ACL or Sequence of the path policy, see docs/PathPolicy.md.

func HopPredicateFromString

func HopPredicateFromString(str string) (*HopPredicate, error)

func NewHopPredicate

func NewHopPredicate() *HopPredicate

func (*HopPredicate) MarshalJSON

func (hp *HopPredicate) MarshalJSON() ([]byte, error)

func (HopPredicate) String

func (hp HopPredicate) String() string

func (*HopPredicate) UnmarshalJSON

func (hp *HopPredicate) UnmarshalJSON(b []byte) error

type Option

type Option struct {
	Weight int        `json:"weight"`
	Policy *ExtPolicy `json:"policy"`
}

Option contains a weight and a policy and is used as a list item in Policy.Options

type Path

type Path interface {
	// Interfaces returns all the interfaces of this path.
	Interfaces() []PathInterface
	// Returns a string that uniquely identifies this path.
	Key() string
}

Path describes a path or a partial path, e.g. a segment.

type PathInterface

type PathInterface interface {
	// IfId is the id of the interface.
	IfId() common.IFIDType
	// IA is the ISD AS identifier of the interface.
	IA() addr.IA
}

PathInterface is an interface on the path.

type PathSet

type PathSet map[string]Path

PathSet is a set of paths. PathSet is used for policy filtering.

type Policy

type Policy struct {
	Name     string    `json:"-"`
	ACL      *ACL      `json:"acl,omitempty"`
	Sequence *Sequence `json:"sequence,omitempty"`
	Options  []Option  `json:"options,omitempty"`
}

Policy is a compiled path policy object, all extended policies have been merged.

func NewPolicy

func NewPolicy(name string, acl *ACL, sequence *Sequence, options []Option) *Policy

NewPolicy creates a Policy and sorts its Options

func PolicyFromExtPolicy

func PolicyFromExtPolicy(extPolicy *ExtPolicy, extended []*ExtPolicy) (*Policy, error)

PolicyFromExtPolicy creates a Policy from an extending Policy and the extended policies

func (*Policy) Filter

func (p *Policy) Filter(paths PathSet) PathSet

Filter filters the path set according to the policy.

func (*Policy) FilterOpt

func (p *Policy) FilterOpt(paths PathSet, opts FilterOptions) PathSet

FilterOpt filters the path set according to the policy with the given options.

type PolicyMap

type PolicyMap map[string]*ExtPolicy

PolicyMap is a container for Policies, keyed by their unique name. PolicyMap can be used to marshal Policies to JSON. Unmarshaling back to PolicyMap is guaranteed to yield an object that is identical to the initial one.

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

func NewSequence

func NewSequence(s string) (*Sequence, error)

NewSequence creates a new sequence from a string

func (*Sequence) Eval

func (s *Sequence) Eval(inputSet PathSet) PathSet

Eval evaluates the interface sequence list and returns the set of paths that match the list

func (*Sequence) MarshalJSON

func (s *Sequence) MarshalJSON() ([]byte, error)

func (*Sequence) UnmarshalJSON

func (s *Sequence) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL