netlist

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright (C) 2020, 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

This section is empty.

Functions

This section is empty.

Types

type IPv6

type IPv6 [2]uint64

IPv6 represents a ipv6 addr

func Conv

func Conv(ip net.IP) (ipv6 IPv6)

Conv converts ip to type IPv6. ip must be a valid 16-byte ipv6 address or Conv() will panic

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 ipv4 addr. Cause we use bin search.

func NewListFromReader

func NewListFromReader(reader io.Reader) (*List, error)

NewListFromReader read IP list from a reader, if no valid IP addr was found, it will return a empty NetList, NOT nil. NetList will be a sorted list.

func NewNetList

func NewNetList() *List

NewNetList returns a NetList, list can not be nil.

func (*List) Append

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

Append appends new Nets to the list. This modified list, call Sort() before call next 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

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, call Sort() before call next Contains()

func (*List) Sort

func (list *List) Sort()

Sort sorts the list, this must be called everytime after list was modified.

func (*List) Swap

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

type Matcher

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

func BatchLoad added in v0.22.0

func BatchLoad(f []string) (m Matcher, err error)

BatchLoad is helper func to load multiple files using NewIPMatcherFromFile.

func NewIPMatcherFromFile

func NewIPMatcherFromFile(file string) (Matcher, error)

NewIPMatcherFromFile loads a netlist file a list or geoip file. if file contains a ':' and has format like 'geoip:cn', file must be a geoip file.

func NewListFromListFile

func NewListFromListFile(file string) (Matcher, error)

NewListFromListFile read IP list from a file, the returned NetList is already been sorted.

func NewNetListFromDAT

func NewNetListFromDAT(file, tag string) (Matcher, error)

type MatcherGroup

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

func NewMatcherGroup

func NewMatcherGroup(m []Matcher) *MatcherGroup

func (*MatcherGroup) Match

func (mg *MatcherGroup) 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 uint) (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.

type V2Matcher

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

func NewV2Matcher

func NewV2Matcher(cidr []*router.CIDR) (*V2Matcher, error)

func (*V2Matcher) Match

func (m *V2Matcher) Match(ip net.IP) bool

Jump to

Keyboard shortcuts

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