netlist

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIP = errors.New("invalid ip")
)
View Source
var LoadFromDATFunc func(l *List, file, tag string) error

Functions

func BatchLoad

func BatchLoad(l *List, entries []string) error

BatchLoad is a helper func to load multiple files using Load. It might modify the List and causes List unsorted.

func BatchLoadFromFiles

func BatchLoadFromFiles(l *List, files []string) error

func Load

func Load(l *List, entry string) error

Load loads data from entry. If entry begin with "ext:", Load loads the file by using LoadFromFile. Else it loads the entry as a text pattern by using LoadFromText.

func LoadFromDAT

func LoadFromDAT(l *List, file, tag string) error

func LoadFromFile

func LoadFromFile(l *List, file string) error

LoadFromFile loads ip from a text file or a geoip file. If file contains a ':' and has format like 'geoip:cn', it will be read as a geoip file. It might modify the List and causes List unsorted.

func LoadFromReader

func LoadFromReader(l *List, reader io.Reader) error

LoadFromReader loads IP list from a reader. It might modify the List and causes List unsorted.

func LoadFromText

func LoadFromText(l *List, s string) error

LoadFromText loads an IP from s. It might modify the List and causes List unsorted.

func LoadFromTextFile

func LoadFromTextFile(l *List, file string) error

LoadFromTextFile reads IP list from a text file. It might modify the List and causes List unsorted.

func ParseIP

func ParseIP(s string) (IPv6, IPVersion, error)

Types

type IPVersion

type IPVersion uint8
const (
	Version4 IPVersion = iota
	Version6
)

type IPv6

type IPv6 [2]uint64

IPv6 represents a ipv6 addr

func Conv

func Conv(ip net.IP) (IPv6, error)

Conv converts ip to type IPv6. ip should be an ipv4/6 address (with length 4 or 16) Conv will return ErrInvalidIP if ip has an invalid length.

func (IPv6) ToNetIP

func (ip IPv6) ToNetIP() net.IP

type List

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

List is a list of Nets. All Nets will be in ipv6 format, even it's an ipv4 addr. Because we use bin search.

func NewList

func NewList() *List

NewList returns a *List.

func (*List) Append

func (list *List) Append(newNet ...Net)

Append appends new Nets to the list. This modified list. Caller must call List.Sort() before calling List.Contains()

func (*List) Contains

func (list *List) Contains(ip net.IP) bool

Contains reports whether the list includes given ip. list must be sorted, or Contains will panic.

func (*List) Len

func (list *List) Len() int

Len implements sort Interface.

func (*List) Less

func (list *List) Less(i, j int) bool

Less implements sort Interface.

func (*List) Match

func (list *List) Match(ip net.IP) bool

func (*List) Merge

func (list *List) Merge(srcList *List)

Merge merges srcList with list This modified list. Caller must call List.Sort() before calling List.Contains()

func (*List) Sort

func (list *List) Sort()

Sort sorts the list, this must be called after list was modified and before call List.Contains().

func (*List) Swap

func (list *List) Swap(i, j int)

Swap implements sort Interface.

type Matcher

type Matcher interface {
	Match(ip net.IP) bool
}

type Net

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

Net represents a ip network

func NewNet

func NewNet(ipv6 IPv6, m int) Net

NewNet returns a new IPNet, mask should be an ipv6 mask, which means you should +96 if you have an ipv4 mask.

func ParseCIDR

func ParseCIDR(s string) (Net, error)

ParseCIDR parses s as a CIDR notation IP address and prefix length. As defined in RFC 4632 and RFC 4291.

func (Net) Contains

func (n Net) Contains(ip IPv6) bool

Contains reports whether the net includes the ip.

func (Net) String

func (n Net) String() string

func (Net) ToNetIPNet

func (n Net) ToNetIPNet() *net.IPNet

Jump to

Keyboard shortcuts

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