samples/pktgen/functions.sh
Source file repositories/reference/linux-study-clean/samples/pktgen/functions.sh
File Facts
- System
- Linux kernel
- Corpus path
samples/pktgen/functions.sh- Extension
.sh- Size
- 8871 bytes
- Lines
- 341
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: samples
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function errfunction pg_ctrlfunction pgsetfunction trap_exitfunction root_check_run_with_sudofunction get_iface_nodefunction get_iface_irqsfunction get_node_cpusfunction extend_addr6function validate_addrfunction validate_addr6function parse_addrfunction parse_addr6function parse_ports
Annotated Snippet
function err() {
local exitcode=$1
shift
echo "ERROR: $@" >&2
exit $exitcode
}
function warn() {
echo "WARN : $@" >&2
}
function info() {
if [[ -n "$VERBOSE" ]]; then
echo "INFO : $@" >&2
fi
}
## -- Pktgen proc config commands -- ##
export PROC_DIR=/proc/net/pktgen
#
# Three different shell functions for configuring the different
# components of pktgen:
# pg_ctrl(), pg_thread() and pg_set().
#
# These functions correspond to pktgens different components.
# * pg_ctrl() control "pgctrl" (/proc/net/pktgen/pgctrl)
# * pg_thread() control the kernel threads and binding to devices
# * pg_set() control setup of individual devices
function pg_ctrl() {
local proc_file="pgctrl"
proc_cmd ${proc_file} "$@"
}
function pg_thread() {
local thread=$1
local proc_file="kpktgend_${thread}"
shift
proc_cmd ${proc_file} "$@"
}
function pg_set() {
local dev=$1
local proc_file="$dev"
shift
proc_cmd ${proc_file} "$@"
}
# More generic replacement for pgset(), that does not depend on global
# variable for proc file.
function proc_cmd() {
local result
local proc_file=$1
local status=0
# after shift, the remaining args are contained in $@
shift
local proc_ctrl=${PROC_DIR}/$proc_file
if [[ ! -e "$proc_ctrl" ]]; then
err 3 "proc file:$proc_ctrl does not exists (dev added to thread?)"
else
if [[ ! -w "$proc_ctrl" ]]; then
err 4 "proc file:$proc_ctrl not writable, not root?!"
fi
fi
if [[ "$DEBUG" == "yes" ]]; then
echo "cmd: $@ > $proc_ctrl"
fi
# Quoting of "$@" is important for space expansion
echo "$@" > "$proc_ctrl" || status=$?
Annotation
- Detected declarations: `function err`, `function pg_ctrl`, `function pgset`, `function trap_exit`, `function root_check_run_with_sudo`, `function get_iface_node`, `function get_iface_irqs`, `function get_node_cpus`, `function extend_addr6`, `function validate_addr`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.