ipset

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

README

ipset

netlink ipset package for Go.

Usage

Your code:
package main

import (
	"log"

	"github.com/notutensil/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")
	
	// ipv4 timeout, do not create if it exists
	ipset.Add("myset", "3.3.3.4", ipset.OptTimeout(60), ipset.OptExcl())

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

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

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

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

AddAddr adds an addr to the named set.

func AddPrefix

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

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

DelAddr deletes an addr from the named set.

func DelPrefix

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

DelPrefix deletes a cidr from the named set.

func Destroy

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

func Init() (err error)

Init prepares a netlink socket of ipset.

Types

type Option

type Option = netlink.Option

Option is used to set parameters of ipset operations.

func OptExcl

func OptExcl() Option

func OptIPv6

func OptIPv6() Option

OptIPv6 sets `family inet6` parameter to operations.

func OptTimeout

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