kubernetes: k8s.io/kubernetes/pkg/util/ipset Index | Files | Directories

package ipset

import "k8s.io/kubernetes/pkg/util/ipset"


Package Files

ipset.go types.go


const (
    // ProtocolFamilyIPV4 represents IPv4 protocol.
    ProtocolFamilyIPV4 = "inet"
    // ProtocolFamilyIPV6 represents IPv6 protocol.
    ProtocolFamilyIPV6 = "inet6"
    // ProtocolTCP represents TCP protocol.
    ProtocolTCP = "tcp"
    // ProtocolUDP represents UDP protocol.
    ProtocolUDP = "udp"
    // ProtocolSCTP represents SCTP protocol.
    ProtocolSCTP = "sctp"
const DefaultPortRange string = "0-65535"

DefaultPortRange defines the default bitmap:port valid port range.

const IPSetCmd = "ipset"

IPSetCmd represents the ipset util. We use ipset command for ipset execute.


var EntryMemberPattern = "(?m)^(.*\n)*Members:\n"

EntryMemberPattern is the regular expression pattern of ipset member list. The raw output of ipset command `ipset list {set}` is similar to, Name: foobar Type: hash:ip,port Revision: 2 Header: family inet hashsize 1024 maxelem 65536 Size in memory: 16592 References: 0 Members:,tcp:8080,udp:53

var ValidIPSetTypes = []Type{

ValidIPSetTypes defines the supported ip set type.

var VersionPattern = "v[0-9]+\\.[0-9]+"

VersionPattern is the regular expression pattern of ipset version string. ipset version output is similar to "v6.10".

func IsNotFoundError Uses

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error indicates "not found". It parses the error string looking for known values, which is imperfect but works in practice.

type Entry Uses

type Entry struct {
    // IP is the entry's IP.  The IP address protocol corresponds to the HashFamily of IPSet.
    // All entries' IP addresses in the same ip set has same the protocol, IPv4 or IPv6.
    IP  string
    // Port is the entry's Port.
    Port int
    // Protocol is the entry's Protocol.  The protocols of entries in the same ip set are all
    // the same.  The accepted protocols are TCP, UDP and SCTP.
    Protocol string
    // Net is the entry's IP network address.  Network address with zero prefix size can NOT
    // be stored.
    Net string
    // IP2 is the entry's second IP.  IP2 may not be empty for `hash:ip,port,ip` type ip set.
    IP2 string
    // SetType is the type of ipset where the entry exists.
    SetType Type

Entry represents a ipset entry.

func (*Entry) String Uses

func (e *Entry) String() string

String returns the string format for ipset entry.

func (*Entry) Validate Uses

func (e *Entry) Validate(set *IPSet) bool

Validate checks if a given ipset entry is valid or not. The set parameter is the ipset that entry belongs to.

type IPSet Uses

type IPSet struct {
    // Name is the set name.
    Name string
    // SetType specifies the ipset type.
    SetType Type
    // HashFamily specifies the protocol family of the IP addresses to be stored in the set.
    // The default is inet, i.e IPv4.  If users want to use IPv6, they should specify inet6.
    HashFamily string
    // HashSize specifies the hash table size of ipset.
    HashSize int
    // MaxElem specifies the max element number of ipset.
    MaxElem int
    // PortRange specifies the port range of bitmap:port type ipset.
    PortRange string
    // comment message for ipset
    Comment string

IPSet implements an Interface to a set.

func (*IPSet) Validate Uses

func (set *IPSet) Validate() bool

Validate checks if a given ipset is valid or not.

type Interface Uses

type Interface interface {
    // FlushSet deletes all entries from a named set.
    FlushSet(set string) error
    // DestroySet deletes a named set.
    DestroySet(set string) error
    // DestroyAllSets deletes all sets.
    DestroyAllSets() error
    // CreateSet creates a new set.  It will ignore error when the set already exists if ignoreExistErr=true.
    CreateSet(set *IPSet, ignoreExistErr bool) error
    // AddEntry adds a new entry to the named set.  It will ignore error when the entry already exists if ignoreExistErr=true.
    AddEntry(entry string, set *IPSet, ignoreExistErr bool) error
    // DelEntry deletes one entry from the named set
    DelEntry(entry string, set string) error
    // Test test if an entry exists in the named set
    TestEntry(entry string, set string) (bool, error)
    // ListEntries lists all the entries from a named set
    ListEntries(set string) ([]string, error)
    // ListSets list all set names from kernel
    ListSets() ([]string, error)
    // GetVersion returns the "X.Y" version string for ipset.
    GetVersion() (string, error)

Interface is an injectable interface for running ipset commands. Implementations must be goroutine-safe.

func New Uses

func New(exec utilexec.Interface) Interface

New returns a new Interface which will exec ipset.

type Type Uses

type Type string

Type represents the ipset type

const (
    // HashIPPort represents the `hash:ip,port` type ipset.  The hash:ip,port is similar to hash:ip but
    // you can store IP address and protocol-port pairs in it.  TCP, SCTP, UDP, UDPLITE, ICMP and ICMPv6 are supported
    // with port numbers/ICMP(v6) types and other protocol numbers without port information.
    HashIPPort Type = "hash:ip,port"
    // HashIPPortIP represents the `hash:ip,port,ip` type ipset.  The hash:ip,port,ip set type uses a hash to store
    // IP address, port number and a second IP address triples.  The port number is interpreted together with a
    // protocol (default TCP) and zero protocol number cannot be used.
    HashIPPortIP Type = "hash:ip,port,ip"
    // HashIPPortNet represents the `hash:ip,port,net` type ipset.  The hash:ip,port,net set type uses a hash to store IP address, port number and IP network address triples.  The port
    // number is interpreted together with a protocol (default TCP) and zero protocol number cannot be used.   Network address
    // with zero prefix size cannot be stored either.
    HashIPPortNet Type = "hash:ip,port,net"
    // BitmapPort represents the `bitmap:port` type ipset.  The bitmap:port set type uses a memory range, where each bit
    // represents one TCP/UDP port.  A bitmap:port type of set can store up to 65535 ports.
    BitmapPort Type = "bitmap:port"



Package ipset imports 8 packages (graph) and is imported by 40 packages. Updated 2019-02-20. Refresh now. Tools for package owners.