netlist

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: GPL-3.0 Imports: 17 Imported by: 1

Documentation

Overview

Copyright (C) 2020-2021, IrineSistiana

This file is part of mosdns.

mosdns is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

mosdns is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidIP = errors.New("invalid ip")
)

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 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

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

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

func LoadGeoIPListFromDAT

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 added in v1.5.1

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) Grow

func (list *List) Grow(n int)

Grow increases list's cap to n.

func (*List) Len

func (list *List) Len() int

implement sort Interface

func (*List) Less

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

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)

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, mask int) (n 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 (net Net) Contains(ip IPv6) bool

Contains reports whether the net includes the ip.

func (Net) String added in v1.5.1

func (n Net) String() string

func (Net) ToNetIPNet added in v1.5.1

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

Jump to

Keyboard shortcuts

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