netlist

package
v3.9.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: GPL-3.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIP = errors.New("invalid ip")
)
View Source
var ErrNotSorted = errors.New("list is not sorted")

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

LoadFromDAT loads ip from v2ray proto file. It might modify the List and causes List unsorted.

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 LoadFromV2CIDR added in v3.9.0

func LoadFromV2CIDR(l *List, cidr []*v2data.CIDR) error

LoadFromV2CIDR loads ip from v2ray CIDR. It might modify the List and causes List unsorted.

func LoadGeoIPFromDAT added in v3.9.0

func LoadGeoIPFromDAT(file, tag string) (*v2data.GeoIP, error)

func LoadGeoIPListFromDAT added in v3.9.0

func LoadGeoIPListFromDAT(file string) (*v2data.GeoIPList, error)

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 Net. It stores all Net in one single slice and use binary search. It is suitable for large static cidr search.

func NewList

func NewList() *List

NewList returns a *List.

func NewListFrom added in v3.1.0

func NewListFrom(l []Net) *List

NewListFrom returns a *List using l as its initial contents. The new List takes ownership of l, and the caller should not use l after this call.

func (*List) Append

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

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

func (*List) Contains

func (list *List) Contains(ipv6 IPv6) (bool, error)

Contains reports whether the list includes the given ipv6.

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, error)

func (*List) Merge

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

Merge merges srcList with list This modified the 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 being modified and before calling 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, error)
}

type Net

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

Net represents an 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