ipset

package module
v0.0.0-...-75b14f6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2015 License: MIT Imports: 3 Imported by: 2

README

go-ipset

Build Status GoDoc

go-ipset provides basic bindings for the ipset kernel utility.

Installation

go get github.com/gmccue/go-ipset

Usage

The following are some basic usage examples for go-iptables. For more information, please checkout the godoc.

import "github.com/gmccue/ipset"

// Construct a new ipset instance
ipset, err := ipset.New()
if err != nil {
    // Your custom error handling here.
}

// Create a new set
err := ipset.Create("my_set", "hash:ip")
if err != nil {
    // Your custom error handling here.
}
Adding an entry to an ipset
err := ipset.Add("my_set", "127.0.0.1")
if err != nil {
    // Your custom error handling here.
}
Removing an entry from an ipset
if err != nil {
    // Your custom error handling here.
}
Save your ipset to a file
err := ipset.Save("my_set", "/tmp/my_set.txt")
if err != nil {
    // Your custom error handling here.
}
Restore your ipset from a file
err := ipset.Restore("/tmp/my_set.txt")
if err != nil {
    // Your custom error handling here.
}

Documentation

Overview

Package ipset provides a basic wrapper to the ipset utility for IPTables. More information about ipset can be found at: http://ipset.netfilter.org/index.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPSet

type IPSet struct {
	Path    string
	Options []string
}

func New

func New() (*IPSet, error)

func (*IPSet) Add

func (set *IPSet) Add(name string, entry string, options ...string) error

Add adds a new entry to the named set.

func (*IPSet) AddUnique

func (set *IPSet) AddUnique(name, entry string, options ...string) error

AddUnique adds a new entry to the named set, if it does not already exist.

func (*IPSet) Create

func (set *IPSet) Create(name string, typ string, options ...string) error

Create creates a new ipset with a given name and type. For more on set types, please see: http://ipset.netfilter.org/ipset.man.html#lbAT. Additional options can be passed to the Create() command. These options must be passed in a sequential key, value order. For example, ipset.Create("test", "hash:ip", "timeout", "300") will add a new set with the timeout option set to a value of 300.

func (*IPSet) Delete

func (set *IPSet) Delete(name string, entry string, options ...string) error

Delete removes an entry from the named set.

func (*IPSet) Destroy

func (set *IPSet) Destroy(name string) error

Destroy destroys a named set, or all sets.

func (*IPSet) Flush

func (set *IPSet) Flush(name string) error

Flush removes all entries from a named set.

func (*IPSet) Rename

func (set *IPSet) Rename(from string, to string) error

Rename changes a set name from one value to another.

func (*IPSet) Restore

func (set *IPSet) Restore(filename string) error

Restore restores a saved set from the given file.

func (*IPSet) Save

func (set *IPSet) Save(name string, filename string) error

Save saves the named set or all sets to the given file.

func (*IPSet) Swap

func (set *IPSet) Swap(from string, to string) error

Swap swaps the content of two existing sets.

func (*IPSet) Test

func (set *IPSet) Test(name string, entry string, options ...string) error

Test tests if an entry exists in the named set. The exit status is zero if the tested entry is in the set, and nonzero if it is missing from the set.

Jump to

Keyboard shortcuts

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