Documentation
¶
Overview ¶
Package util provides generic utility routines used within FSM CNI Plugin.
Index ¶
- Constants
- Variables
- func ARPing(srcIP, dstIP net.IP, iface net.Interface) (net.HardwareAddr, error)
- func AtomicCopy(srcFilepath, targetDir, targetFilename string) error
- func AtomicWrite(path string, data []byte, mode os.FileMode) (err error)
- func CreateFileWatcher(dirs ...string) (watcher *fsnotify.Watcher, fileModified chan bool, errChan chan error, ...)
- func DirEquals(a, b string) (bool, error)
- func Exists(name string) bool
- func GetDefaultGatewayAddr(iface net.Interface) (net.IP, error)
- func GetPlugin(rawPlugin any) (plugin map[string]any, err error)
- func GetPlugins(cniConfigMap map[string]any) (plugins []any, err error)
- func HostToNetLong(i uint32) uint32
- func HostToNetShort(i uint16) uint16
- func IPToInt(ipaddr net.IP) (addr0, addr1, addr2, addr4 uint32, v6 uint8, err error)
- func IPv4ToInt(ipaddr net.IP) (uint32, error)
- func IPv6ToInt4(ipaddr net.IP) ([4]uint32, error)
- func Inode(path string) (uint64, error)
- func Int4ToIPv6(v6Ints [4]uint32) net.IP
- func IntToIPv4(ipaddr uint32) net.IP
- func IsDirWriteable(dir string) error
- func MarshalCNIConfig(cniConfigMap map[string]any) ([]byte, error)
- func Mount(source string, target string, fstype string, flags uintptr, data string) (err error)
- func NetToHostLong(i uint32) uint32
- func NetToHostShort(i uint16) uint16
- func ParseIP(s string) (net.IP, int, error)
- func Uptime() uint64
- func WaitForFileMod(ctx context.Context, fileModified chan bool, errChan chan error) error
- type LinuxSocket
Constants ¶
const (
// PrivateFileMode grants owner to read/write a file.
PrivateFileMode = 0o600
)
Variables ¶
var ErrInvalidIPAddress = errors.New("invalid ip address")
var ErrNotIPv4Address = errors.New("not an IPv4 address")
var ErrNotIPv6Address = errors.New("not an IPv6 address")
Functions ¶
func AtomicCopy ¶
AtomicCopy copies file by reading the file then writing atomically into the target directory
func AtomicWrite ¶
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 GetPlugin ¶
GetPlugin given the raw plugin interface, return the plugin asserted as a map[string]interface{}
func GetPlugins ¶
GetPlugins given an unmarshalled CNI config JSON map, return the plugin list asserted as a []interface{}
func HostToNetLong ¶
HostToNetLong converts a 32-bit integer from host to network byte order, aka "htonl"
func HostToNetShort ¶
HostToNetShort converts a 16-bit integer from host to network byte order, aka "htons"
func IPv6ToInt4 ¶
IPv6ToInt4 converts IP address of version 6 from net.IP to [4]uint32 representation.
func Int4ToIPv6 ¶
Int4ToIPv6 converts IP address of version 6 from [4]uint32 to net.IP representation.
func IsDirWriteable ¶
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 ¶
MarshalCNIConfig marshal the CNI config map and append a new line
func NetToHostLong ¶
NetToHostLong converts a 32-bit integer from network to host byte order, aka "ntohl"
func NetToHostShort ¶
NetToHostShort converts a 16-bit integer from network to host byte order, aka "ntohs"
Types ¶
type LinuxSocket ¶
type LinuxSocket struct {
// contains filtered or unexported fields
}