ipset

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: GPL-3.0 Imports: 2 Imported by: 11

README

ipset

Go Report Card GitHub tag PkgGoDev Go Version

netlink ipset package for Go.

Usage

Your code:
package main

import (
	"log"

	"github.com/nadoo/ipset"
)

func main() {
	// must call Init first
	if err := ipset.Init(); err != nil {
		log.Printf("error in ipset Init: %s", err)
		return
	}

	// default is ipv4 without timeout
	ipset.Destroy("myset")
	ipset.Create("myset")
	ipset.Add("myset", "1.1.1.1")
	ipset.Add("myset", "2.2.2.0/24")

	// ipv6 and timeout example
	// ipset create myset6 hash:net family inet6 timeout 60
	ipset.Create("myset6", ipset.OptIPv6(), ipset.OptTimeout(60))
	ipset.Flush("myset6")

	ipset.Add("myset6", "2022::1", ipset.OptTimeout(10))
	ipset.Add("myset6", "2022::1/32")
}
Result:

ipset list myset

Name: myset
Type: hash:net
Revision: 1
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 552
References: 0
Number of entries: 2
Members:
1.1.1.1
2.2.2.0/24

ipset list myset6

Name: myset6
Type: hash:net
Revision: 1
Header: family inet6 hashsize 1024 maxelem 65536 timeout 60
Size in memory: 1432
References: 0
Number of entries: 2
Members:
2022::1 timeout 9
2022::/32 timeout 59
  • glider: a forward proxy with ipset management features powered by this package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(setName, entry string, opts ...Option) (err error)

Add adds an entry to the named set. entry could be: "1.1.1.1" or "192.168.1.0/24" or "2022::1" or "2022::1/32".

func AddAddr added in v0.5.0

func AddAddr(setName string, ip netip.Addr, opts ...Option) (err error)

AddAddr adds an addr to the named set.

func AddPrefix added in v0.5.0

func AddPrefix(setName string, cidr netip.Prefix, opts ...Option) (err error)

AddPrefix adds a cidr to the named set.

func Create

func Create(setName string, opts ...Option) (err error)

Create creates a new set.

func Del

func Del(setName, entry string) (err error)

Del deletes an entry from the named set. entry could be: "1.1.1.1" or "192.168.1.0/24" or "2022::1" or "2022::1/32".

func DelAddr added in v0.5.0

func DelAddr(setName string, ip netip.Addr) (err error)

DelAddr deletes an addr from the named set.

func DelPrefix added in v0.5.0

func DelPrefix(setName string, cidr netip.Prefix) (err error)

DelPrefix deletes a cidr from the named set.

func Destroy added in v0.3.0

func Destroy(setName string) (err error)

Destroy destroys a named set.

func Flush

func Flush(setName string) (err error)

Flush flushes a named set.

func Init added in v0.2.0

func Init() (err error)

Init prepares a netlink socket of ipset.

Types

type Option added in v0.4.0

type Option = netlink.Option

Option is used to set parameters of ipset operations.

func OptIPv6 added in v0.4.0

func OptIPv6() Option

OptIPv6 sets `family inet6` parameter to operations.

func OptTimeout added in v0.4.0

func OptTimeout(timeout uint32) Option

OptTimeout sets `timeout xx` parameter to operations.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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