ipset

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: GPL-3.0 Imports: 1 Imported by: 11

README

ipset

GitHub tag PkgGoDev

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.Destroy("myset6")
	// ipset create myset6 hash:net family inet6 timeout 60
	ipset.Create("myset6", ipset.OptIPv6(), ipset.OptTimeout(60))
	ipset.Flush("myset6")

	ipset.Add("myset6", "2404:6800:4005:812::200e", ipset.OptTimeout(10))
	ipset.Add("myset6", "2404:6800:4005:812::/64")
}
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:
2404:6800:4005:812::/64 timeout 56
2404:6800:4005:812::200e timeout 6
  • 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".

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.

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