networking

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package networking contains interfaces to the database models for Network ACLs and Routes.

Package networking contains interfaces to the database models for Network ACLs and Routes.

Index

Constants

View Source
const (
	// BootstrapNodesNetworkACLName is the name of the bootstrap nodes NetworkACL.
	BootstrapNodesNetworkACLName = "bootstrap-nodes"
	// NetworkACLsPrefix is where NetworkACLs are stored in the database.
	NetworkACLsPrefix = "/registry/network-acls"
	// RoutesPrefix is where Routes are stored in the database.
	RoutesPrefix = "/registry/routes"
)

Variables

View Source
var ErrACLNotFound = errors.New("network acl not found")

ErrACLNotFound is returned when a NetworkACL is not found.

View Source
var ErrRouteNotFound = errors.New("route not found")

ErrRouteNotFound is returned when a Route is not found.

Functions

func IsSystemNetworkACL

func IsSystemNetworkACL(name string) bool

IsSystemNetworkACL returns true if the NetworkACL is a system NetworkACL.

Types

type ACL

type ACL struct {
	*v1.NetworkACL
	// contains filtered or unexported fields
}

ACL is a Network ACL. It contains a reference to the database for evaluating group membership.

func (*ACL) Matches

func (acl *ACL) Matches(ctx context.Context, action *v1.NetworkAction) bool

Matches checks if an action matches this ACL. If a database query fails it will log the error and return false.

func (*ACL) Proto

func (a *ACL) Proto() *v1.NetworkACL

Proto returns the protobuf representation of the ACL.

type ACLs

type ACLs []*ACL

ACLs is a list of Network ACLs. It contains methods for evaluating actions against contained permissions. It also allows for sorting by priority.

func (ACLs) Accept

func (a ACLs) Accept(ctx context.Context, action *v1.NetworkAction) bool

Accept evaluates an action against the ACLs in the list. It assumes the ACLs are sorted by priority. The first ACL that matches the action will be used. If no ACL matches, the action is denied.

func (ACLs) Len

func (a ACLs) Len() int

Len returns the length of the ACLs list.

func (ACLs) Less

func (a ACLs) Less(i, j int) bool

Less returns whether the ACL at index i should be sorted before the ACL at index j.

func (ACLs) Proto

func (a ACLs) Proto() []*v1.NetworkACL

Proto returns the protobuf representation of the ACLs.

func (ACLs) Sort

func (a ACLs) Sort(direction SortDirection)

Sort sorts the ACLs by priority.

func (ACLs) Swap

func (a ACLs) Swap(i, j int)

Swap swaps the ACLs at the given indices.

type AdjacencyMap

type AdjacencyMap map[string]map[string]graph.Edge[string]

AdjacencyMap is a map of node names to a map of node names to edges.

type Networking

type Networking interface {
	// PutNetworkACL creates or updates a NetworkACL.
	PutNetworkACL(ctx context.Context, acl *v1.NetworkACL) error
	// GetNetworkACL returns a NetworkACL by name.
	GetNetworkACL(ctx context.Context, name string) (*ACL, error)
	// DeleteNetworkACL deletes a NetworkACL by name.
	DeleteNetworkACL(ctx context.Context, name string) error
	// ListNetworkACLs returns a list of NetworkACLs.
	ListNetworkACLs(ctx context.Context) (ACLs, error)

	// PutRoute creates or updates a Route.
	PutRoute(ctx context.Context, route *v1.Route) error
	// GetRoute returns a Route by name.
	GetRoute(ctx context.Context, name string) (*v1.Route, error)
	// GetRoutesByNode returns a list of Routes for a given Node.
	GetRoutesByNode(ctx context.Context, nodeName string) ([]*v1.Route, error)
	// GetRoutesByCIDR returns a list of Routes for a given CIDR.
	GetRoutesByCIDR(ctx context.Context, cidr string) ([]*v1.Route, error)
	// DeleteRoute deletes a Route by name.
	DeleteRoute(ctx context.Context, name string) error
	// ListRoutes returns a list of Routes.
	ListRoutes(ctx context.Context) ([]*v1.Route, error)

	// FilterGraph filters the adjacency map in the given graph for the given node name according
	// to the current network ACLs. If the ACL list is nil, an empty adjacency map is returned. An
	// error is returned on faiure building the initial map or any database error.
	FilterGraph(ctx context.Context, peerGraph peers.Graph, nodeName string) (AdjacencyMap, error)
}

Networking is the interface to the database models for network resources.

func New

func New(st storage.Storage) Networking

New returns a new Networking interface.

type SortDirection

type SortDirection int

SortDirection is the direction to sort ACLs.

const (
	// SortDescending sorts ACLs in descending order.
	SortDescending SortDirection = iota
	// SortAscending sorts ACLs in ascending order.
	SortAscending
)

Jump to

Keyboard shortcuts

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