Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ declare imds_endpoint=""
declare imds_token=""
declare imds_interface=""

# Debug logging: when non-empty, debug messages are sent to syslog.
# Set via environment (e.g. systemd: Environment=EC2_NET_UTILS_DEBUG=1) or
# uncomment the next line for temporary local debugging:
# EC2_NET_UTILS_DEBUG=1
: "${EC2_NET_UTILS_DEBUG:=}"

make_token_request() {
local ep=${1:-""}
local interface=${2:-""}
Expand Down Expand Up @@ -124,8 +130,12 @@ log() {
logger --id=$$ --priority "${syslog_facility}.${priority}" --tag "$syslog_tag" "$@"
}

# When EC2_NET_UTILS_DEBUG is set (e.g. 1, true, yes), debug messages are logged.
# Omit the variable or set it empty to suppress debug (default).
debug() {
log debug "$@"
if [ -n "${EC2_NET_UTILS_DEBUG:-}" ]; then
log debug "$@"
fi
}

info() {
Expand Down Expand Up @@ -326,7 +336,7 @@ create_rules() {
# response.
addrs=$(get_iface_imds ${ether} ${local_addr_key} || true)
if [[ -z "$addrs" ]]; then
info "No addresses found for ${ether}"
debug "No addresses found for ${iface}"
return 0
fi

Expand Down