ipfilter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ipfilter implements a high performance IP filter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPFilter

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

IPFilter is a high performance, AVL-based IP filter. The filter can be used for filtering any IPv4, IPv6 and IP4-mapped IPv6 addresses.

It's thread-safe for read ops. But if you need to read and write at the same time, a RWLock is necessary.

func NewNonGlobalUnicastIPFilter

func NewNonGlobalUnicastIPFilter() *IPFilter

NewNonGlobalUnicastIPFilter returns a new IPFilter which can filter out all the non-global unicast IPv4 and IPv6 IPs.

func NewNonPublicIPFilter

func NewNonPublicIPFilter() *IPFilter

NewNonPublicIPFilter returns a new IPFilter which can filter out all the non-public IPv4 and IPv6 IPs, such as private addresses.

func (*IPFilter) Add

func (f *IPFilter) Add(addr string) error

Add an IP or a CIDR address into the filter. The addr can be a IP, such as "192.168.0.1", or a CIDR notation, like "192.0.2.0/24" or "2001:db8::/32" .

To add mutliple IP / CIDR addresses into the filter, you can simply call it multi times.

func (*IPFilter) Search

func (f *IPFilter) Search(addr string) (bool, error)

Search parses addr as an IP address, and checks if it's in the filter. If addr is not an IPv4 or IPv6 address, a non-nil error will be returned. If addr is in the filter, it will return (true, nil).

func (*IPFilter) SearchIP

func (f *IPFilter) SearchIP(ip net.IP) (bool, error)

SearchIP checks if the ip is in the filter. If addr is not an IPv4 or IPv6 address, a non-nil error will be returned. If addr is in the filter, it will return (true, nil).

Jump to

Keyboard shortcuts

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