netool

package
v2.10.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRelayIP

func CheckRelayIP(sender, addr net.IP) error

CheckRelayIP reports whether an IP relayed from the given sender IP is a valid connection target.

There are four rules:

  • Special network addresses are never valid.
  • Loopback addresses are OK if relayed by a loopback host.
  • LAN addresses are OK if relayed by a LAN host.
  • All other addresses are always acceptable.

func IsLAN

func IsLAN(ip net.IP) bool

IsLAN reports whether an IP is a local network address.

func IsSpecialNetwork

func IsSpecialNetwork(ip net.IP) bool

IsSpecialNetwork reports whether an IP is located in a special-use network range This includes broadcast, multicast and documentation addresses.

func SameNet

func SameNet(bits uint, ip, other net.IP) bool

SameNet reports whether two IP addresses have an equal prefix of the given bit length.

Types

type BlackList

type BlackList interface {
	Ban([]byte, int64)
	UnBan([]byte)
	Banned([]byte) bool
}

func NewBlackList

func NewBlackList(strategy Strategy) BlackList

type DistinctNetSet

type DistinctNetSet struct {
	Subnet uint // number of common prefix bits
	Limit  uint // maximum number of IPs in each subnet
	// contains filtered or unexported fields
}

DistinctNetSet tracks IPs, ensuring that at most N of them fall into the same network range.

func (*DistinctNetSet) Add

func (s *DistinctNetSet) Add(ip net.IP) bool

Add adds an IP address to the set. It returns false (and doesn't add the IP) if the number of existing IPs in the defined range exceeds the limit.

func (DistinctNetSet) Contains

func (s DistinctNetSet) Contains(ip net.IP) bool

Contains whether the given IP is contained in the set.

func (DistinctNetSet) Len

func (s DistinctNetSet) Len() int

Len returns the number of tracked IPs.

func (*DistinctNetSet) Remove

func (s *DistinctNetSet) Remove(ip net.IP)

Remove removes an IP from the set.

func (DistinctNetSet) String

func (s DistinctNetSet) String() string

String implements fmt.Stringer

type Netlist

type Netlist []net.IPNet

Netlist is a list of IP networks.

func ParseNetlist

func ParseNetlist(s string) (*Netlist, error)

ParseNetlist parses a comma-separated list of CIDR masks. Whitespace and extra commas are ignored.

func (*Netlist) Add

func (l *Netlist) Add(cidr string)

Add parses a CIDR mask and appends it to the list. It panics for invalid masks and is intended to be used for setting up static lists.

func (*Netlist) Contains

func (l *Netlist) Contains(ip net.IP) bool

Contains reports whether the given IP is contained in the list.

func (Netlist) MarshalTOML

func (l Netlist) MarshalTOML() interface{}

MarshalTOML implements toml.MarshalerRec.

func (*Netlist) UnmarshalTOML

func (l *Netlist) UnmarshalTOML(fn func(interface{}) error) error

UnmarshalTOML implements toml.UnmarshalerRec.

type Strategy

type Strategy func(t int64, count int) bool

Strategy receive first ban time and ban count, return true means banned

Jump to

Keyboard shortcuts

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