netutils

package
v0.0.0-...-8dd92da Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIPRoute

func AddIPRoute(cidr, gw string) error

AddIPRoute adds the specified ip route

func CIDRToMask

func CIDRToMask(cidr string) (int, error)

CIDRToMask converts a CIDR to corresponding network number

func ClearBitsOutsideRange

func ClearBitsOutsideRange(ipAllocMap *bitset.BitSet, ipRange string, subnetLen uint)

ClearBitsOutsideRange sets all IPs outside range as used

func ClearIPAddrRange

func ClearIPAddrRange(ipAllocMap *bitset.BitSet, ipPool string, nwSubnetIP string, nwSubnetLen uint) error

ClearIPAddrRange marks range of IP address as used

func ClearReservedEntries

func ClearReservedEntries(b *bitset.BitSet, subnetLen uint)

ClearReservedEntries clears reserved bits

func ConvertBandwidth

func ConvertBandwidth(bandwidth string) int64

ConvertBandwidth will change the format of the bandwidth to int64 format and return the updated bw. eg:- 2 kb bandwidth will be converted to 2*1024 and the result in Int64 format will be returned.

func CreateBitset

func CreateBitset(numBitsWide uint) *bitset.BitSet

CreateBitset initializes a bit set with 2^numBitsWide bits

func DelIPRoute

func DelIPRoute(cidr, gw string) error

DelIPRoute deletes the specified ip route

func GetDefaultAddr

func GetDefaultAddr() (string, error)

GetDefaultAddr gets default address of local hostname

func GetFirstLocalAddr

func GetFirstLocalAddr() (string, error)

GetFirstLocalAddr returns the first ip address

func GetHostIntfName

func GetHostIntfName(intf string) string

GetHostIntfName gets the host access interface name

func GetIPAddrRange

func GetIPAddrRange(ipCIDR string, subnetLen uint) string

GetIPAddrRange returns IP CIDR as a ip address range

func GetIPNumber

func GetIPNumber(subnetIP string, subnetLen uint, allocSubnetLen uint, hostIP string) (uint, error)

GetIPNumber obtains the host id from the host IP. SEe `GetSubnetIP` for more information.

func GetIPv6HostID

func GetIPv6HostID(subnetAddr string, subnetLen uint, hostAddr string) (string, error)

GetIPv6HostID obtains the host id from the host IP. SEe `GetSubnetIP` for more information.

func GetInterfaceIP

func GetInterfaceIP(linkName string) (string, error)

GetInterfaceIP obtains the ip addr of a local interface on the host.

func GetLocalAddrList

func GetLocalAddrList() ([]string, error)

GetLocalAddrList returns a list of local IP addresses

func GetMyAddr

func GetMyAddr() (string, error)

GetMyAddr returns ip address of current host

func GetNetlinkAddrList

func GetNetlinkAddrList() ([]string, error)

GetNetlinkAddrList returns a list of local IP addresses

func GetNextIPv6HostID

func GetNextIPv6HostID(hostID, subnetAddr string, subnetLen uint, IPv6AllocMap map[string]bool) (string, error)

GetNextIPv6HostID returns the next available hostId in the AllocMap

func GetSubnetAddr

func GetSubnetAddr(ipStr string, length uint) string

GetSubnetAddr returns a subnet given a subnet range

func GetSubnetIP

func GetSubnetIP(subnetIP string, subnetLen uint, allocSubnetLen, hostID uint) (string, error)

GetSubnetIP given a subnet IP and host identifier, calculates an IP within the subnet for use.

func GetSubnetIPv6

func GetSubnetIPv6(subnetAddr string, subnetLen uint, hostID string) (string, error)

GetSubnetIPv6 given a subnet IP and host identifier, calculates an IPv6 address within the subnet for use.

func HostIPToGateway

func HostIPToGateway(hostIP string) (string, error)

HostIPToGateway gets the gateway based on the IP

func InitSubnetBitset

func InitSubnetBitset(b *bitset.BitSet, subnetLen uint)

InitSubnetBitset initializes a bit set with 2^(32 - subnetLen) bits

func IsAddrLocal

func IsAddrLocal(findAddr string) bool

IsAddrLocal check if an address is local

func IsIPv6

func IsIPv6(ip string) bool

IsIPv6 Checks if the address string is IPv6 address

func IsOverlappingSubnet

func IsOverlappingSubnet(inputSubnet string, existingSubnet string) bool

IsOverlappingSubnet verifies the Overlapping of subnet

func IsOverlappingSubnetv6

func IsOverlappingSubnetv6(inputIPv6Subnet string, existingIPv6Subnet string) bool

IsOverlappingSubnetv6 verifies the Overlapping of subnet for v6 networks

func ListAllocatedIPs

func ListAllocatedIPs(allocMap bitset.BitSet, ipPool string, subnetIP string, subnetLen uint) string

ListAllocatedIPs returns a string of allocated IPs in a network

func ListAvailableIPs

func ListAvailableIPs(allocMap bitset.BitSet, subnetIP string, subnetLen uint) string

ListAvailableIPs returns a string of available IPs in a network

func NextClear

func NextClear(allocMap bitset.BitSet, idx uint, subnetLen uint) (uint, bool)

NextClear wrapper around Bitset to check max id

func ParseCIDR

func ParseCIDR(cidrStr string) (string, uint, error)

ParseCIDR parses a CIDR string into a gateway IP and length.

func PortToHostIPMAC

func PortToHostIPMAC(port, subnet int) (string, string)

PortToHostIPMAC gets IP and MAC based on port number

func ReserveIPv6HostID

func ReserveIPv6HostID(hostID string, IPv6AllocMap *map[string]bool)

ReserveIPv6HostID sets the hostId in the AllocMap

func SetBitsOutsideRange

func SetBitsOutsideRange(ipAllocMap *bitset.BitSet, ipRange string, subnetLen uint)

SetBitsOutsideRange sets all IPs outside range as used

func SetIPAddrRange

func SetIPAddrRange(ipAllocMap *bitset.BitSet, ipPool string, nwSubnetIP string,
	nwSubnetLen uint) error

SetIPAddrRange marks range of IP address as used

func SetIPMasquerade

func SetIPMasquerade(intf, netmask string) error

SetIPMasquerade sets a ip masquerade rule.

func SetInterfaceIP

func SetInterfaceIP(name string, ipstr string) error

SetInterfaceIP : Set IP address of an interface

func SetInterfaceMac

func SetInterfaceMac(name string, macaddr string) error

SetInterfaceMac : Set mac address of an interface

func TestIPAddrRange

func TestIPAddrRange(ipAllocMap *bitset.BitSet, ipPool string, nwSubnetIP string,
	nwSubnetLen uint) error

TestIPAddrRange checks if any IP address from the subnet is already used

func ValidateBindAddress

func ValidateBindAddress(address string) error

ValidateBindAddress format in "address:port"

func ValidateNetworkRangeParams

func ValidateNetworkRangeParams(ipRange string, subnetLen uint) error

ValidateNetworkRangeParams verifies the network range format

Types

type TagRange

type TagRange struct {
	Min int
	Max int
}

TagRange represents a range of integers, intended for VLAN and VXLAN tagging.

func ParseTagRanges

func ParseTagRanges(ranges string, tagType string) ([]TagRange, error)

ParseTagRanges takes a string such as 12-24,48-64 and turns it into a series of TagRange.

Jump to

Keyboard shortcuts

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