Documentation ¶
Overview ¶
Package kernel is utilities for the Linux kernel
Index ¶
- Variables
- func AllPidsProcs(procRoot string) ([]int, error)
- func Arch() string
- func GetCurrentIno() (uint32, error)
- func GetInoForNs(ns netns.NsHandle) (uint32, error)
- func GetKernelHeaders(opts HeaderOptions, client statsd.ClientInterface) []string
- func GetNetNamespaceFromPid(procRoot string, pid int) (netns.NsHandle, error)
- func GetNetNamespaces(procRoot string) ([]netns.NsHandle, error)
- func GetNetNsInoFromPid(procRoot string, pid int) (uint32, error)
- func GetProcessEnvVariable(pid int, procRoot string, envVar string) (string, error)
- func GetRootNetNamespace(procRoot string) (netns.NsHandle, error)
- func HostProc(combineWith ...string) string
- func IsIPv6Enabled() bool
- func MountInfoPidPath(pid int32) string
- func ParseMountInfoFile(pid int32) ([]*mountinfo.Info, error)
- func WithAllProcs(procRoot string, fn func(int) error) error
- func WithNS(ns netns.NsHandle, fn func() error) error
- func WithRootNS(procRoot string, fn func() error) error
- type HeaderOptions
- type LockdownMode
- type UbuntuKernelVersion
- type Version
Constants ¶
This section is empty.
Variables ¶
var Family = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.family, err
})
Family is the string describing the Linux distribution family (rhel, debian, etc.)
var HeaderProvider *headerProvider
HeaderProvider is a global object which is responsible for managing the fetching of kernel headers
var Machine = funcs.Memoize(func() (string, error) { u, err := uname() if err != nil { return "", err } return unix.ByteSliceToString(u.Machine[:]), nil })
Machine is the equivalent of uname -m
var OnlineCPUs = funcs.Memoize(func() ([]uint, error) {
return parseCPUMultipleRangeFromFile("/sys/devices/system/cpu/online")
})
OnlineCPUs returns the individual CPU numbers that are online for the system
var Platform = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.platform, err
})
Platform is the string describing the Linux distribution (ubuntu, debian, fedora, etc.)
var PlatformVersion = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.version, err
})
PlatformVersion is the string describing the platform version (`22.04` for Ubuntu jammy, etc.)
var PossibleCPUs = funcs.Memoize(func() (int, error) {
return parseCPUSingleRangeFromFile("/sys/devices/system/cpu/possible")
})
PossibleCPUs returns the max number of CPUs a system may possibly have Logical CPU numbers must be of the form 0-n
var ProcFSRoot = funcs.MemoizeNoError(func() string { if v := os.Getenv("HOST_PROC"); v != "" { return v } if os.Getenv("DOCKER_DD_AGENT") != "" { if _, err := os.Stat("/host"); err == nil { return "/host/proc" } } return "/proc" })
ProcFSRoot retrieves the current procfs dir we should use
var Release = funcs.Memoize(func() (string, error) { u, err := uname() if err != nil { return "", err } return unix.ByteSliceToString(u.Release[:]), nil })
Release is the equivalent of uname -r
var RootNSPID = funcs.Memoize(func() (int, error) { pidPath := filepath.Join(ProcFSRoot(), "self") pidStr, err := os.Readlink(pidPath) if err != nil { return 0, err } return strconv.Atoi(pidStr) })
RootNSPID returns the current PID from the root namespace
var SysFSRoot = funcs.MemoizeNoError(func() string { if v := os.Getenv("HOST_SYS"); v != "" { return v } if os.Getenv("DOCKER_DD_AGENT") != "" { if _, err := os.Stat("/host"); err == nil { return "/host/sys" } } return "/sys" })
SysFSRoot retrieves the current sysfs dir we should use
var UnameVersion = funcs.Memoize(func() (string, error) { u, err := uname() if err != nil { return "", err } return unix.ByteSliceToString(u.Version[:]), nil })
UnameVersion is the equivalent of uname -v
Functions ¶
func AllPidsProcs ¶
AllPidsProcs will return all pids under procRoot
func Arch ¶
func Arch() string
Arch returns the kernel architecture value, often used within the kernel `include/arch` directory.
func GetCurrentIno ¶
GetCurrentIno returns the ino number for the current network namespace
func GetInoForNs ¶
GetInoForNs gets the inode number for the given network namespace
func GetKernelHeaders ¶
func GetKernelHeaders(opts HeaderOptions, client statsd.ClientInterface) []string
GetKernelHeaders fetches and returns kernel headers for the currently running kernel.
The first time GetKernelHeaders is called, it will search the host for kernel headers, and if they cannot be found it will attempt to download headers to the configured header download directory.
Any subsequent calls to GetKernelHeaders will return the result of the first call. This is because kernel header downloading can be a resource intensive process, so we don't want to retry it an unlimited number of times.
func GetNetNamespaceFromPid ¶
GetNetNamespaceFromPid gets the network namespace for a given `pid`
func GetNetNamespaces ¶
GetNetNamespaces returns a list of network namespaces on the machine. The caller is responsible for calling Close() on each of the returned NsHandle's.
func GetNetNsInoFromPid ¶
GetNetNsInoFromPid gets the network namespace inode number for the given `pid`
func GetProcessEnvVariable ¶
GetProcessEnvVariable retrieves the given environment variable for the specified process ID, without loading the entire environment into memory. Will return an empty string if the variable is not found.
func GetRootNetNamespace ¶
GetRootNetNamespace gets the root network namespace
func HostProc ¶
HostProc returns the location of a host's procfs. This can and will be overridden when running inside a container.
func IsIPv6Enabled ¶
func IsIPv6Enabled() bool
IsIPv6Enabled returns whether IPv6 has been enabled on the host
func MountInfoPidPath ¶
MountInfoPidPath returns the path to the mountinfo file of a pid in /proc
func ParseMountInfoFile ¶
ParseMountInfoFile collects the mounts for a specific process ID.
func WithAllProcs ¶
WithAllProcs will execute `fn` for every pid under procRoot. `fn` is passed the `pid`. If `fn` returns an error the iteration aborts, returning the last error returned from `fn`.
func WithNS ¶
WithNS executes the given function in the given network namespace, and then switches back to the previous namespace.
func WithRootNS ¶
WithRootNS executes a function within root network namespace and then switch back to the previous namespace. If the thread is already in the root network namespace, the function is executed without calling SYS_SETNS.
Types ¶
type HeaderOptions ¶
type HeaderOptions struct { DownloadEnabled bool Dirs []string DownloadDir string AptConfigDir string YumReposDir string ZypperReposDir string }
HeaderOptions are options for the kernel header download process
type LockdownMode ¶
type LockdownMode string
LockdownMode defines a lockdown type
const ( // None mode None LockdownMode = "none" // Integrity mode Integrity LockdownMode = "integrity" // Confidentiality mode Confidentiality LockdownMode = "confidentiality" // Unknown mode Unknown LockdownMode = "unknown" )
type UbuntuKernelVersion ¶
UbuntuKernelVersion represents a version from an ubuntu kernel Please see: https://ubuntu.com/kernel for the documentation of this scheme
func NewUbuntuKernelVersion ¶
func NewUbuntuKernelVersion(unameRelease string) (*UbuntuKernelVersion, error)
NewUbuntuKernelVersion parses the ubuntu release string and returns a structure with each extracted fields
type Version ¶
type Version uint32
Version is a numerical representation of a kernel version
func HostVersion ¶
HostVersion returns the running kernel version of the host
func MustHostVersion ¶
func MustHostVersion() Version
MustHostVersion returns the running kernel version of the host
func ParseReleaseString ¶
ParseReleaseString converts a release string with format 4.4.2[-1] to a kernel version number in LINUX_VERSION_CODE format. That is, for kernel "a.b.c", the version number will be (a<<16 + b<<8 + c)
func ParseVersion ¶
ParseVersion parses a string in the format of x.x.x to a Version
func VersionCode ¶
VersionCode returns a Version computed from the individual parts of a x.x.x version