util

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package util provides generic utility routines used within FSM CNI Plugin.

Index

Constants

View Source
const (
	// PrivateFileMode grants owner to read/write a file.
	PrivateFileMode = 0o600
)

Variables

View Source
var ErrInvalidIPAddress = errors.New("invalid ip address")
View Source
var ErrNotIPv4Address = errors.New("not an IPv4 address")
View Source
var ErrNotIPv6Address = errors.New("not an IPv6 address")

Functions

func ARPing

func ARPing(srcIP, dstIP net.IP, iface net.Interface) (net.HardwareAddr, error)

ARPing sends an arp ping over interface 'iface' to 'dstIP'

func AtomicCopy

func AtomicCopy(srcFilepath, targetDir, targetFilename string) error

AtomicCopy copies file by reading the file then writing atomically into the target directory

func AtomicWrite

func AtomicWrite(path string, data []byte, mode os.FileMode) (err error)

AtomicWrite atomically by writing to a temporary file in the same directory then renaming

func CreateFileWatcher

func CreateFileWatcher(dirs ...string) (watcher *fsnotify.Watcher, fileModified chan bool, errChan chan error, err error)

CreateFileWatcher creates a file watcher that watches for any changes to the directory

func DirEquals

func DirEquals(a, b string) (bool, error)

DirEquals check if two directories are referring to the same directory

func Exists

func Exists(name string) bool

Exists checks whether the file exists

func GetDefaultGatewayAddr

func GetDefaultGatewayAddr(iface net.Interface) (net.IP, error)

func GetPlugin

func GetPlugin(rawPlugin any) (plugin map[string]any, err error)

GetPlugin given the raw plugin interface, return the plugin asserted as a map[string]interface{}

func GetPlugins

func GetPlugins(cniConfigMap map[string]any) (plugins []any, err error)

GetPlugins given an unmarshalled CNI config JSON map, return the plugin list asserted as a []interface{}

func HostToNetLong

func HostToNetLong(i uint32) uint32

HostToNetLong converts a 32-bit integer from host to network byte order, aka "htonl"

func HostToNetShort

func HostToNetShort(i uint16) uint16

HostToNetShort converts a 16-bit integer from host to network byte order, aka "htons"

func IPToInt

func IPToInt(ipaddr net.IP) (addr0, addr1, addr2, addr4 uint32, v6 uint8, err error)

func IPv4ToInt

func IPv4ToInt(ipaddr net.IP) (uint32, error)

IPv4ToInt converts IP address of version 4 from net.IP to uint32 representation.

func IPv6ToInt4

func IPv6ToInt4(ipaddr net.IP) ([4]uint32, error)

IPv6ToInt4 converts IP address of version 6 from net.IP to [4]uint32 representation.

func Inode

func Inode(path string) (uint64, error)

Inode returns the inode of file

func Int4ToIPv6

func Int4ToIPv6(v6Ints [4]uint32) net.IP

Int4ToIPv6 converts IP address of version 6 from [4]uint32 to net.IP representation.

func IntToIPv4

func IntToIPv4(ipaddr uint32) net.IP

IntToIPv4 converts IP address of version 4 from uint32 to net.IP representation.

func IsDirWriteable

func IsDirWriteable(dir string) error

IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable. Inspired by etcd fileutil.

func MarshalCNIConfig

func MarshalCNIConfig(cniConfigMap map[string]any) ([]byte, error)

MarshalCNIConfig marshal the CNI config map and append a new line

func Mount

func Mount(source string, target string, fstype string, flags uintptr, data string) (err error)

func NetToHostLong

func NetToHostLong(i uint32) uint32

NetToHostLong converts a 32-bit integer from network to host byte order, aka "ntohl"

func NetToHostShort

func NetToHostShort(i uint16) uint16

NetToHostShort converts a 16-bit integer from network to host byte order, aka "ntohs"

func ParseIP

func ParseIP(s string) (net.IP, int, error)

ParseIP implements extension of net.ParseIP. It returns additional information about IP address bytes length. In general, it works typically as standard net.ParseIP. So if IP is not valid, nil is returned.

func Uptime

func Uptime() uint64

func WaitForFileMod

func WaitForFileMod(ctx context.Context, fileModified chan bool, errChan chan error) error

WaitForFileMod waits until a file is modified (returns nil), the context is cancelled (returns context error), or returns error

Types

type LinuxSocket

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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