netutils2

package
v0.3.10-0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 17 Imported by: 1

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 MASKS = []string{"0", "128", "192", "224", "240", "248", "252", "254", "255"}
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, privatePrefixes []string)

func DefaultSrcIpDev

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

func ErrMacFormat

func ErrMacFormat(macStr 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)

Types

type SMacAddr

type SMacAddr [6]byte

func ParseMac

func ParseMac(macStr string) (SMacAddr, error)

func (SMacAddr) Add

func (mac SMacAddr) Add(step int) SMacAddr

func (SMacAddr) String

func (mac SMacAddr) String() string

type SNetInterface

type SNetInterface struct {
	Addr string
	Mask net.IPMask
	Mac  string

	Mtu int
	// contains filtered or unexported fields
}

func NewNetInterface

func NewNetInterface(name string) *SNetInterface

func NewNetInterfaceWithExpectIp

func NewNetInterfaceWithExpectIp(name string, expectIp string) *SNetInterface

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) 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

Jump to

Keyboard shortcuts

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