netutils2

package
v0.0.0-...-6410feb Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SECRET_PREFIX   = "169.254"
	SECRET_MASK     = []byte{255, 255, 255, 255}
	SECRET_MASK_LEN = 32
)
View Source
var PRIVATE_PREFIXES = []string{
	"10.0.0.0/8",
	"172.16.0.0/12",
	"192.168.0.0/16",
}
View Source
var PSEUDO_VIP = "169.254.169.231"

Functions

func AddNicRoutes

func AddNicRoutes(routes [][]string, nicDesc *types.SServerNic, mainIp string, nicCnt int) [][]string

func DefaultSrcIpDev

func DefaultSrcIpDev() (srcIp net.IP, ifname string, err error)

func ExpandCompactIps

func ExpandCompactIps(ipstr string) ([]string, error)

func FormatMac

func FormatMac(macStr string) string

func GetFreePort

func GetFreePort() (int, error)

func GetHttpRequestIp

func GetHttpRequestIp(r *http.Request) string

func GetMainNicFromDeployApi

func GetMainNicFromDeployApi(nics []*types.SServerNic) (*types.SServerNic, error)

func GetNicDns

func GetNicDns(nicdesc *types.SServerNic) []string

func GetPrivatePrefixes

func GetPrivatePrefixes(privatePrefixes []string) []string

func GetSecretInterfaceAddress

func GetSecretInterfaceAddress() (string, int)

func IsTcpPortUsed

func IsTcpPortUsed(addr string, port int) bool

func MacEqual

func MacEqual(mac1, mac2 string) bool

func MyIP

func MyIP() (ip string, err error)

MyIP returns source ip used to communicate with udp:114.114.114.114

func MyIPTo

func MyIPTo(dstIP string) (ip string, err error)

MyIPTo returns source ip used to communicate with udp:dstIP

func NetBytes2Mask

func NetBytes2Mask(mask []byte) string

func Netlen2Mask

func Netlen2Mask(netmasklen int) string

func Netmask2Len

func Netmask2Len(mask string) int

func PrefixSplit

func PrefixSplit(pref string) (string, int, error)

func TestTcpPort

func TestTcpPort(ip string, port int, timeoutSecs int, tries int) error

func WaitIfaceIps

func WaitIfaceIps(ifname string) (*net.Interface, []net.IP, error)

Types

type SBondingConfig

type SBondingConfig struct {
	Mode     int
	ModeName string
	Slaves   []string
}

type SNetInterface

type SNetInterface struct {
	Addr string
	Mask net.IPMask

	Mtu int

	VlanId     int
	VlanParent *SNetInterface

	BondingMode   int
	BondingSlaves []*SNetInterface
	// contains filtered or unexported fields
}

func NewNetInterface

func NewNetInterface(name string) *SNetInterface

func NewNetInterfaceWithExpectIp

func NewNetInterfaceWithExpectIp(name string, expectIp string) *SNetInterface

func (*SNetInterface) ClearAddrs

func (n *SNetInterface) ClearAddrs() error

func (*SNetInterface) Exist

func (n *SNetInterface) Exist() bool

func (*SNetInterface) FetchConfig

func (n *SNetInterface) FetchConfig()

func (*SNetInterface) FetchInter

func (n *SNetInterface) FetchInter() *net.Interface

func (*SNetInterface) GetAddresses

func (n *SNetInterface) GetAddresses() [][]string

func (*SNetInterface) GetAllMacs

func (n *SNetInterface) GetAllMacs() []string

func (*SNetInterface) GetMac

func (n *SNetInterface) GetMac() string

func (*SNetInterface) GetRouteSpecs

func (n *SNetInterface) GetRouteSpecs() []iproute2.RouteSpec

func (*SNetInterface) GetSlaveAddresses

func (n *SNetInterface) GetSlaveAddresses() [][]string

func (*SNetInterface) IsSecretAddress

func (n *SNetInterface) IsSecretAddress(addr string, mask []byte) bool

func (*SNetInterface) IsSecretInterface

func (n *SNetInterface) IsSecretInterface() bool

func (*SNetInterface) SetupGso

func (n *SNetInterface) SetupGso(on bool)

https://kris.io/2015/10/01/kvm-network-performance-tso-and-gso-turn-it-off/ General speaking, it is recommended to turn of GSO however, this will degrade host network performance

func (*SNetInterface) String

func (n *SNetInterface) String() string

type SNicInfo

type SNicInfo struct {
	IpAddr  string
	Gateway string
	MacAddr string
}

type SNicInfoList

type SNicInfoList []SNicInfo

func (SNicInfoList) Add

func (nics SNicInfoList) Add(ip, mac, gw string) SNicInfoList

func (SNicInfoList) FindDefaultNicMac

func (nics SNicInfoList) FindDefaultNicMac() (string, int)

type SVlanConfig

type SVlanConfig struct {
	Ifname string
	VlanId int
	Parent string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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