netset

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 14 Imported by: 15

Documentation

Overview

Package netset implements types for network connection sets objects and operations. Types defined in this package: IPBlock - captures a set of IP ranges TCPUDPSet - captures sets of protocols (within TCP,UDP only) and ports (source and destination) ICMPSet - captures sets of type,code values for ICMP protocol TransportSet - captures union of elements from TCPUDPSet, ICMPSet EndpointsTrafficSet - captures a set of traffic attribute for tuples of (source IP range, destination IP range, TransportSet)

Index

Constants

View Source
const (
	// CidrAll represents the CIDR for all addresses "0.0.0.0/0"
	CidrAll = "0.0.0.0/0"

	FirstIPAddressString = "0.0.0.0"
	LastIPAddressString  = "255.255.255.255"
)
View Source
const (
	AllConnections = "All Connections"
	NoConnections  = "No Connections"
)
View Source
const (
	TCPCode = 0
	UDPCode = 1
)

encoding TCP/UDP protocols as integers for TCPUDPSet

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeSet

type CodeSet = interval.CanonicalSet

func AllICMPCodes

func AllICMPCodes() *CodeSet

type Details

type Details spec.ProtocolList

func ToJSON

func ToJSON(c *TransportSet) Details

ToJSON returns a `Details` object for JSON representation of the input connection Set.

type EndpointsTrafficSet

type EndpointsTrafficSet struct {
	// contains filtered or unexported fields
}

EndpointsTrafficSet captures a set of traffic attributes for tuples of (source IP range, desination IP range, TransportSet), where TransportSet is a set of TCP/UPD/ICMP with their properties (src,dst ports / icmp type,code)

func EmptyEndpointsTrafficSet

func EmptyEndpointsTrafficSet() *EndpointsTrafficSet

EmptyEndpointsTrafficSet returns an empty EndpointsTrafficSet

func NewEndpointsTrafficSet

func NewEndpointsTrafficSet(src, dst *IPBlock, conn *TransportSet) *EndpointsTrafficSet

NewEndpointsTrafficSet returns a new EndpointsTrafficSet object from input src, dst IP-ranges sets ands TransportSet connections

func (*EndpointsTrafficSet) Copy

Copy returns new EndpointsTrafficSet object with same set of connections as current one

func (*EndpointsTrafficSet) Equal

func (c *EndpointsTrafficSet) Equal(other *EndpointsTrafficSet) bool

Equal returns true is this EndpointsTrafficSet captures the exact same set of connections as `other` does.

func (*EndpointsTrafficSet) Intersect

Intersect returns a EndpointsTrafficSet object with connection tuples that result from intersection of this and `other` sets

func (*EndpointsTrafficSet) IsEmpty

func (c *EndpointsTrafficSet) IsEmpty() bool

IsEmpty returns true of the EndpointsTrafficSet is empty

func (*EndpointsTrafficSet) IsSubset

func (c *EndpointsTrafficSet) IsSubset(other *EndpointsTrafficSet) bool

IsSubset returns true if c is subset of other

func (*EndpointsTrafficSet) Partitions

func (c *EndpointsTrafficSet) Partitions() []ds.Triple[*IPBlock, *IPBlock, *TransportSet]

func (*EndpointsTrafficSet) String

func (c *EndpointsTrafficSet) String() string

func (*EndpointsTrafficSet) Subtract

Subtract returns a EndpointsTrafficSet object with connection tuples that result from subtraction of `other` from this set

func (*EndpointsTrafficSet) Union

Union returns a EndpointsTrafficSet object with connection tuples that result from union of this and `other` sets

type ICMPSet

type ICMPSet struct {
	// contains filtered or unexported fields
}

func AllICMPSet

func AllICMPSet() *ICMPSet

func EmptyICMPSet

func EmptyICMPSet() *ICMPSet

func ICMPSetFromICMP added in v0.5.5

func ICMPSetFromICMP(icmp netp.ICMP) *ICMPSet

func NewICMPSet

func NewICMPSet(minType, maxType, minCode, maxCode int64) *ICMPSet

func (*ICMPSet) Copy

func (c *ICMPSet) Copy() *ICMPSet

func (*ICMPSet) Equal

func (c *ICMPSet) Equal(other *ICMPSet) bool

func (*ICMPSet) Hash

func (c *ICMPSet) Hash() int

func (*ICMPSet) Intersect

func (c *ICMPSet) Intersect(other *ICMPSet) *ICMPSet

func (*ICMPSet) IsAll

func (c *ICMPSet) IsAll() bool

func (*ICMPSet) IsEmpty

func (c *ICMPSet) IsEmpty() bool

func (*ICMPSet) IsSubset

func (c *ICMPSet) IsSubset(other *ICMPSet) bool

IsSubset returns true if c is subset of other

func (*ICMPSet) Partitions

func (c *ICMPSet) Partitions() []ds.Pair[*TypeSet, *CodeSet]

func (*ICMPSet) Size

func (c *ICMPSet) Size() int

func (*ICMPSet) String

func (c *ICMPSet) String() string

func (*ICMPSet) Subtract

func (c *ICMPSet) Subtract(other *ICMPSet) *ICMPSet

Subtract returns the subtraction of the other from c

func (*ICMPSet) Union

func (c *ICMPSet) Union(other *ICMPSet) *ICMPSet

type IPBlock

type IPBlock struct {
	// contains filtered or unexported fields
}

IPBlock captures a set of IP ranges

func DisjointIPBlocks

func DisjointIPBlocks(set1, set2 []*IPBlock) []*IPBlock

DisjointIPBlocks returns an IPBlock of disjoint ip ranges from 2 input IPBlock objects

func GetCidrAll

func GetCidrAll() *IPBlock

GetCidrAll returns IPBlock object of the entire range 0.0.0.0/0

func GetFirstIPAddress added in v0.5.1

func GetFirstIPAddress() *IPBlock

GetFirstIPAddress returns IPBlock object of 0.0.0.0

func GetLastIPAddress added in v0.5.1

func GetLastIPAddress() *IPBlock

GetLastIPAddress returns IPBlock object of 255.255.255.255

func IPBlockFromCidr

func IPBlockFromCidr(cidr string) (*IPBlock, error)

IPBlockFromCidr returns a new IPBlock object from input CIDR string

func IPBlockFromCidrList

func IPBlockFromCidrList(cidrsList []string) (*IPBlock, error)

IPBlockFromCidrList returns IPBlock object from multiple CIDRs given as list of strings

func IPBlockFromCidrOrAddress

func IPBlockFromCidrOrAddress(s string) (*IPBlock, error)

IPBlockFromCidrOrAddress returns a new IPBlock object from input string of CIDR or IP address

func IPBlockFromIPAddress

func IPBlockFromIPAddress(ipAddress string) (*IPBlock, error)

IPBlockFromIPAddress returns an IPBlock object from input IP address string

func IPBlockFromIPRange added in v0.5.1

func IPBlockFromIPRange(startIP, endIP *IPBlock) (*IPBlock, error)

IPBlockFromIPRange returns a new IPBlock object that contains startIP-endIP

func IPBlockFromIPRangeStr

func IPBlockFromIPRangeStr(ipRangeStr string) (*IPBlock, error)

IPBlockFromIPRangeStr returns IPBlock object from input IP range string (example: "169.255.0.0-172.15.255.255")

func NewIPBlock

func NewIPBlock() *IPBlock

NewIPBlock returns a new IPBlock object

func PairCIDRsToIPBlocks

func PairCIDRsToIPBlocks(cidr1, cidr2 string) (ipb1, ipb2 *IPBlock, err error)

PairCIDRsToIPBlocks returns two IPBlock objects from two input CIDR strings

func (*IPBlock) AsCidr added in v0.5.2

func (b *IPBlock) AsCidr() (string, error)

AsCidr returns the CIDR string of this IPBlock object, if it contains exactly one CIDR, otherwise it returns an error

func (*IPBlock) Compare added in v0.5.3

func (b *IPBlock) Compare(other *IPBlock) int

Compare returns -1 if this<other, 1 if this>other, 0 o.w.

func (*IPBlock) Copy

func (b *IPBlock) Copy() *IPBlock

Copy returns a new copy of IPBlock object

func (*IPBlock) Equal

func (b *IPBlock) Equal(c *IPBlock) bool

Equal returns true if this IPBlock equals the input IPBlock

func (*IPBlock) ExceptCidrs

func (b *IPBlock) ExceptCidrs(exceptions ...string) (*IPBlock, error)

ExceptCidrs returns a new IPBlock with all cidr ranges removed

func (*IPBlock) FirstIPAddress

func (b *IPBlock) FirstIPAddress() string

FirstIPAddress returns the first IP Address string for this IPBlock

func (*IPBlock) FirstIPAddressObject added in v0.5.1

func (b *IPBlock) FirstIPAddressObject() *IPBlock

FirstIPAddressObject returns the first IP Address for this IPBlock

func (*IPBlock) Hash

func (b *IPBlock) Hash() int

func (*IPBlock) Intersect

func (b *IPBlock) Intersect(c *IPBlock) *IPBlock

Intersect returns a new IPBlock from intersection of this IPBlock with input IPBlock

func (*IPBlock) IsEmpty

func (b *IPBlock) IsEmpty() bool

IsEmpty returns true if this IPBlock is empty

func (*IPBlock) IsSingleIPAddress added in v0.5.1

func (b *IPBlock) IsSingleIPAddress() bool

IsSingleIPAddress returns true if this ipblock is a single IP address

func (*IPBlock) IsSubset

func (b *IPBlock) IsSubset(other *IPBlock) bool

IsSubset checks if this IP block is contained within another IP block.

func (*IPBlock) LastIPAddress added in v0.5.1

func (b *IPBlock) LastIPAddress() string

LastIPAddress returns the last IP Address string for this IPBlock

func (*IPBlock) LastIPAddressObject added in v0.5.1

func (b *IPBlock) LastIPAddressObject() *IPBlock

LastIPAddressObject returns the last IP Address for this IPBlock

func (*IPBlock) ListToPrint

func (b *IPBlock) ListToPrint() []string

ListToPrint returns a uniform to print list s.t. each element contains either a single cidr or an ip range

func (*IPBlock) NextIP added in v0.5.1

func (b *IPBlock) NextIP() (*IPBlock, error)

NextIP returns the next ip address after this IPBlock

func (*IPBlock) Overlap

func (b *IPBlock) Overlap(c *IPBlock) bool

Overlap returns whether the two IPBlocks have at least one IP address in common

func (*IPBlock) PrefixLength

func (b *IPBlock) PrefixLength() (int64, error)

PrefixLength returns the cidr's prefix length, assuming the ipBlock is exactly one cidr. Prefix length specifies the number of bits in the IP address that are to be used as the subnet mask.

func (*IPBlock) PreviousIP added in v0.5.1

func (b *IPBlock) PreviousIP() (*IPBlock, error)

PreviousIP returns the previous ip address before this IPBlock

func (*IPBlock) Size

func (b *IPBlock) Size() int

func (*IPBlock) Split

func (b *IPBlock) Split() []*IPBlock

Split returns a set of IPBlock objects, each with a single range of ips

func (*IPBlock) SplitToCidrs added in v0.5.1

func (b *IPBlock) SplitToCidrs() []*IPBlock

SplitToCidrs returns a slice of IPBlocks, each representing a single CIDR

func (*IPBlock) String

func (b *IPBlock) String() string

String returns an IPBlock's string -- either single IP address, or list of CIDR strings

func (*IPBlock) Subtract

func (b *IPBlock) Subtract(c *IPBlock) *IPBlock

Subtract returns a new IPBlock from subtraction of input IPBlock from this IPBlock

func (*IPBlock) ToCidrList

func (b *IPBlock) ToCidrList() []string

ToCidrList returns a list of CIDR strings for this IPBlock object

func (*IPBlock) ToCidrListString

func (b *IPBlock) ToCidrListString() string

ToCidrListString returns a string with all CIDRs within the IPBlock object

func (*IPBlock) ToIPAddressString

func (b *IPBlock) ToIPAddressString() string

ToIPAddressString returns the IP Address string for this IPBlock

func (*IPBlock) ToIPRanges

func (b *IPBlock) ToIPRanges() string

ToIPRanges returns a string of the ip ranges in the current IPBlock object

func (*IPBlock) TouchingIPRanges added in v0.5.1

func (b *IPBlock) TouchingIPRanges(other *IPBlock) (bool, error)

TouchingIPRanges returns true if this and other ipblocks objects are touching. assumption: both IPBlocks represent a single IP range

func (*IPBlock) Union

func (b *IPBlock) Union(c *IPBlock) *IPBlock

Union returns a new IPBlock from union of input IPBlock with this IPBlock

type PortSet

type PortSet = interval.CanonicalSet // valid range: [1,65535]  (see netp.MinPort , netp.MaxPort)

func AllPorts

func AllPorts() *PortSet

type ProtocolSet

type ProtocolSet = interval.CanonicalSet // valid range: [0,1] (see TCPCode , UDPCode)

func AllTCPUDPProtocolSet

func AllTCPUDPProtocolSet() *ProtocolSet

type RFCICMPSet

type RFCICMPSet uint32

RFCICMPSet is a set of _valid_ (by RFC) ICMP values, encoded as a bitset

func AllICMPSetStrict

func AllICMPSetStrict() *RFCICMPSet

func EmptyICMPSetStrict

func EmptyICMPSetStrict() *RFCICMPSet

func NewICMPSetStrict

func NewICMPSetStrict(t netp.ICMP) *RFCICMPSet

func (*RFCICMPSet) Contains

func (s *RFCICMPSet) Contains(i int) bool

func (*RFCICMPSet) Copy

func (s *RFCICMPSet) Copy() *RFCICMPSet

func (*RFCICMPSet) Equal

func (s *RFCICMPSet) Equal(other *RFCICMPSet) bool

func (*RFCICMPSet) Hash

func (s *RFCICMPSet) Hash() int

func (*RFCICMPSet) Intersect

func (s *RFCICMPSet) Intersect(other *RFCICMPSet) *RFCICMPSet

func (*RFCICMPSet) IsAll

func (s *RFCICMPSet) IsAll() bool

func (*RFCICMPSet) IsEmpty

func (s *RFCICMPSet) IsEmpty() bool

func (*RFCICMPSet) IsSubset

func (s *RFCICMPSet) IsSubset(other *RFCICMPSet) bool

func (*RFCICMPSet) Partitions

func (s *RFCICMPSet) Partitions() []netp.ICMP

Partitions returns a list of ICMP values. if all codes for a given type are present, it adds a single ICMP value with nil Code. If all ICMP values are present, a single ICMP value with nil TypeCode is returned.

func (*RFCICMPSet) Size

func (s *RFCICMPSet) Size() int

func (*RFCICMPSet) String

func (s *RFCICMPSet) String() string

func (*RFCICMPSet) Subtract

func (s *RFCICMPSet) Subtract(other *RFCICMPSet) *RFCICMPSet

func (*RFCICMPSet) Union

func (s *RFCICMPSet) Union(other *RFCICMPSet) *RFCICMPSet

type TCPUDPSet

type TCPUDPSet struct {
	// contains filtered or unexported fields
}

TCPUDPSet captures sets of protocols (within TCP,UDP only) and ports (source and destination)

func AllTCPUDPSet

func AllTCPUDPSet() *TCPUDPSet

func EmptyTCPorUDPSet

func EmptyTCPorUDPSet() *TCPUDPSet

func NewAllTCPOnlySet

func NewAllTCPOnlySet() *TCPUDPSet

func NewAllUDPOnlySet

func NewAllUDPOnlySet() *TCPUDPSet

func NewTCPorUDPSet

func NewTCPorUDPSet(protocolString netp.ProtocolString, srcMinP, srcMaxP, dstMinP, dstMaxP int64) *TCPUDPSet

func (*TCPUDPSet) Copy

func (c *TCPUDPSet) Copy() *TCPUDPSet

func (*TCPUDPSet) Equal

func (c *TCPUDPSet) Equal(other *TCPUDPSet) bool

func (*TCPUDPSet) Hash

func (c *TCPUDPSet) Hash() int

func (*TCPUDPSet) Intersect

func (c *TCPUDPSet) Intersect(other *TCPUDPSet) *TCPUDPSet

func (*TCPUDPSet) IsAll

func (c *TCPUDPSet) IsAll() bool

func (*TCPUDPSet) IsEmpty

func (c *TCPUDPSet) IsEmpty() bool

func (*TCPUDPSet) IsSubset

func (c *TCPUDPSet) IsSubset(other *TCPUDPSet) bool

IsSubset returns true if c is subset of other

func (*TCPUDPSet) Partitions

func (c *TCPUDPSet) Partitions() []ds.Triple[*ProtocolSet, *PortSet, *PortSet]

func (*TCPUDPSet) Size

func (c *TCPUDPSet) Size() int

func (*TCPUDPSet) String

func (c *TCPUDPSet) String() string

func (*TCPUDPSet) Subtract

func (c *TCPUDPSet) Subtract(other *TCPUDPSet) *TCPUDPSet

Subtract returns the subtraction of the other from c

func (*TCPUDPSet) SwapPorts

func (c *TCPUDPSet) SwapPorts() *TCPUDPSet

SwapPorts returns a new TCPUDPSet object, built from the input TCPUDPSet object, with src ports and dst ports swapped

func (*TCPUDPSet) Union

func (c *TCPUDPSet) Union(other *TCPUDPSet) *TCPUDPSet

type TransportSet

type TransportSet struct {
	// contains filtered or unexported fields
}

TransportSet captures connection-sets for protocols from {TCP, UDP, ICMP}

func AllICMPTransport

func AllICMPTransport() *TransportSet

func AllOrNothingTransport

func AllOrNothingTransport(allTcpudp, allIcmp bool) *TransportSet

func AllTCPTransport

func AllTCPTransport() *TransportSet

AllTCPTransport returns a set of connections containing the TCP protocol with all its possible ports

func AllTCPorUDPTransport

func AllTCPorUDPTransport(protocol netp.ProtocolString) *TransportSet

func AllTransports

func AllTransports() *TransportSet

func AllUDPTransport

func AllUDPTransport() *TransportSet

AllUDPTransport returns a set of connections containing the UDP protocol with all its possible ports

func NewICMPTransport

func NewICMPTransport(minType, maxType, minCode, maxCode int64) *TransportSet

func NewICMPTransportFromICMPSet added in v0.5.5

func NewICMPTransportFromICMPSet(icmpSet *ICMPSet) *TransportSet

func NewTCPTransport

func NewTCPTransport(srcMinP, srcMaxP, dstMinP, dstMaxP int64) *TransportSet

NewTCP returns a set of TCP connections containing the specified ports

func NewTCPUDPTransportFromTCPUDPSet added in v0.5.5

func NewTCPUDPTransportFromTCPUDPSet(tcpudpSet *TCPUDPSet) *TransportSet

func NewTCPorUDPTransport

func NewTCPorUDPTransport(protocol netp.ProtocolString, srcMinP, srcMaxP, dstMinP, dstMaxP int64) *TransportSet

func NewUDPTransport

func NewUDPTransport(srcMinP, srcMaxP, dstMinP, dstMaxP int64) *TransportSet

func NoTransports

func NoTransports() *TransportSet

func (*TransportSet) Copy

func (t *TransportSet) Copy() *TransportSet

func (*TransportSet) Equal

func (t *TransportSet) Equal(other *TransportSet) bool

func (*TransportSet) Hash

func (t *TransportSet) Hash() int

func (*TransportSet) ICMPSet

func (t *TransportSet) ICMPSet() *ICMPSet

func (*TransportSet) Intersect

func (t *TransportSet) Intersect(other *TransportSet) *TransportSet

func (*TransportSet) IsAll

func (t *TransportSet) IsAll() bool

func (*TransportSet) IsEmpty

func (t *TransportSet) IsEmpty() bool

func (*TransportSet) IsSubset

func (t *TransportSet) IsSubset(other *TransportSet) bool

IsSubset returns true if c is subset of other

func (*TransportSet) Size

func (t *TransportSet) Size() int

func (*TransportSet) String

func (t *TransportSet) String() string

func (*TransportSet) Subtract

func (t *TransportSet) Subtract(other *TransportSet) *TransportSet

func (*TransportSet) SwapPorts

func (t *TransportSet) SwapPorts() *TransportSet

func (*TransportSet) TCPUDPSet

func (t *TransportSet) TCPUDPSet() *TCPUDPSet

func (*TransportSet) Union

func (t *TransportSet) Union(other *TransportSet) *TransportSet

type TypeSet

type TypeSet = interval.CanonicalSet

func AllICMPTypes

func AllICMPTypes() *TypeSet

Jump to

Keyboard shortcuts

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