util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ParseTimeErrorCode = -1

ParseTimeErrorCode is constant set to -1 to show error

Variables

This section is empty.

Functions

func ChooseHostInterface

func ChooseHostInterface() (net.IP, error)

ChooseHostInterface is a method used fetch an IP for a daemon. If there is no routing info file, it will choose a global IP from the system interfaces. Otherwise, it will use IPv4 and IPv6 route information to return the IP of the interface with a gateway on it (with priority given to IPv4). For a node with no internet connection, it returns error.

func ChooseHostInterfaceFromRoute

func ChooseHostInterfaceFromRoute(routes []Route, nw networkInterfacer) (net.IP, error)

ChooseHostInterfaceFromRoute cycles through each default route provided, looking for a global IP address from the interface for the route. Will first look all each IPv4 route for an IPv4 IP, and then will look at each IPv6 route for an IPv6 IP.

func ChooseIPFromHostInterfaces

func ChooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error)

ChooseIPFromHostInterfaces looks at all system interfaces, trying to find one that is up that has a global unicast address (non-loopback, non-link local, non-point2point), and returns the IP. Searches for IPv4 addresses, and then IPv6 addresses.

func Command

func Command(name string, arg []string) (string, error)

Command executes command and returns output

func ConvertStrToTime

func ConvertStrToTime(strTime string) (time.Time, error)

ConvertStrToTime converts time string object to inbuilt time object

func GetCurPath

func GetCurPath() string

GetCurPath returns filepath

func GetIPFromInterface

func GetIPFromInterface(intfName string, forFamily AddressFamily, nw networkInterfacer) (net.IP, error)

GetIPFromInterface gets the IPs on an interface and returns a global unicast address, if any. The interface must be up, the IP must in the family requested, and the IP must be a global unicast address.

func GetMatchingGlobalIP

func GetMatchingGlobalIP(addrs []net.Addr, family AddressFamily) (net.IP, error)

GetMatchingGlobalIP returns the first valid global unicast address of the given 'family' from the list of 'addrs'.

func IsInterfaceUp

func IsInterfaceUp(intf *net.Interface) bool

IsInterfaceUp checks the interface is running or not

func IsLoopbackOrPointToPoint

func IsLoopbackOrPointToPoint(intf *net.Interface) bool

IsLoopbackOrPointToPoint checks interface is loopback or point to point

func MemberOf

func MemberOf(ip net.IP, family AddressFamily) bool

MemberOf tells if the IP is of the desired family. Used for checking interface addresses.

func NewSourcesReady

func NewSourcesReady() config.SourcesReady

NewSourcesReady returns a new sourceready object

func ParseIP

func ParseIP(str string, family AddressFamily) (net.IP, error)

ParseIP takes the hex IP address string from route file and converts it to a net.IP address. For IPv4, the value must be converted to big endian.

func ParseTimestampInt64

func ParseTimestampInt64(timestamp int64) metav1.Time

ParseTimestampInt64 returns given int64 type time into matav1 type time

func ParseTimestampStr2Int64

func ParseTimestampStr2Int64(s string) (int64, error)

ParseTimestampStr2Int64 returns given string time into int64 type

func ReadDirNoStat

func ReadDirNoStat(dirname string) ([]string, error)

ReadDirNoStat returns a string of files/directories contained in dirname without calling lstat on them.

func ValidateNodeIP

func ValidateNodeIP(nodeIP net.IP) error

ValidateNodeIP validates given node IP belongs to the current host

Types

type AddressFamily

type AddressFamily uint

AddressFamily is uint type var to describe family ips

type Route

type Route struct {
	Interface   string
	Destination net.IP
	Gateway     net.IP
	Family      AddressFamily
}

Route is to define object of connection route

func GetAllDefaultRoutes

func GetAllDefaultRoutes() ([]Route, error)

GetAllDefaultRoutes obtains IPv4 and IPv6 default routes on the node. If unable to read the IPv4 routing info file, we return an error. If unable to read the IPv6 routing info file (which is optional), we'll just use the IPv4 route information. Using all the routing info, if no default routes are found, an error is returned.

func GetIPv4DefaultRoutes

func GetIPv4DefaultRoutes(input io.Reader) ([]Route, error)

GetIPv4DefaultRoutes obtains the IPv4 routes, and filters out non-default routes.

func GetIPv6DefaultRoutes

func GetIPv6DefaultRoutes(input io.Reader) ([]Route, error)

GetIPv6DefaultRoutes obtains the IPv6 routes, and filters out non-default routes.

type RouteFile

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

RouteFile is object of file of routs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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