filter

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: AGPL-3.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int32

Action is an enum modelling all possible filter actions.

const (
	ActionNone Action = iota // zero value.
	ActionAccept
	ActionDeny
)

type Filters

type Filters struct {
	DefaultAction Action
	// contains filtered or unexported fields
}

Filters is a structure representing a collection of accept/deny net.IPNet filters, together with the DefaultAction flag, which represents the default filter policy.

Note that the last policy added to the Filters is authoritative.

func NewFilters

func NewFilters() *Filters

NewFilters constructs and returns a new set of net.IPNet filters. By default, the new filter accepts all addresses.

func (*Filters) ActionForFilter

func (fs *Filters) ActionForFilter(ipnet net.IPNet) (action Action, ok bool)

func (*Filters) AddDialFilter deprecated

func (fs *Filters) AddDialFilter(f *net.IPNet)

AddDialFilter adds a deny rule to this Filters set. Hosts matching the given net.IPNet filter will be denied, unless another rule is added which states that they should be accepted.

No effort is made to prevent duplication of filters, or to simplify the filters list.

Deprecated: Use AddFilter().

func (*Filters) AddFilter

func (fs *Filters) AddFilter(ipnet net.IPNet, action Action)

AddFilter adds a rule to the Filters set, enforcing the desired action for the provided IPNet mask.

func (*Filters) AddrBlocked

func (fs *Filters) AddrBlocked(a ma.Multiaddr) (deny bool)

AddrBlocked parses a ma.Multiaddr and, if a valid netip is found, it applies the Filter set rules, returning true if the given address should be denied, and false if the given address is accepted.

If a parsing error occurs, or no filter matches, the Filters' default is returned.

TODO: currently, the last filter to match wins always, but it shouldn't be that way.

Instead, the highest-specific last filter should win; that way more specific filters
override more general ones.

func (*Filters) Filters deprecated

func (fs *Filters) Filters() (result []*net.IPNet)

Filters returns the list of DENY net.IPNet masks. For backwards compatibility.

A copy of the filters is made prior to returning, so the inner state is not exposed.

Deprecated: Use FiltersForAction().

func (*Filters) FiltersForAction

func (fs *Filters) FiltersForAction(action Action) (result []net.IPNet)

FiltersForAction returns the filters associated with the indicated action.

func (*Filters) Remove deprecated

func (fs *Filters) Remove(ipnet *net.IPNet) (removed bool)

RemoveLiteral removes the first filter associated with the supplied IPNet, returning whether something was removed or not. It makes no distinction between whether the rule is an accept or a deny.

Deprecated: use RemoveLiteral() instead.

func (*Filters) RemoveLiteral

func (fs *Filters) RemoveLiteral(ipnet net.IPNet) (removed bool)

RemoveLiteral removes the first filter associated with the supplied IPNet, returning whether something was removed or not. It makes no distinction between whether the rule is an accept or a deny.

Jump to

Keyboard shortcuts

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