Skip to content

Commit 8fc78f0

Browse files
committed
BE: Better arpo-scan accuracy w/ system optimization
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
1 parent 1a364e2 commit 8fc78f0

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

install/production-filesystem/entrypoint.d/36-override-loaded-plugins.sh renamed to install/production-filesystem/entrypoint.d/36-override-individual-settings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# 36-override-loaded-plugins.sh - Applies environment variable overrides to app.conf
2+
# 36-override-individual-settings.sh - Applies environment variable overrides to app.conf
33

44
set -eu
55

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/sh
2+
3+
# 37-host-optimization.sh: Apply and validate network optimizations (ARP flux fix)
4+
#
5+
# This script improves detection accuracy by ensuring proper ARP behavior.
6+
# It attempts to apply sysctl settings and warns if not possible.
7+
8+
# --- Color Codes ---
9+
RED=$(printf '\033[1;31m')
10+
YELLOW=$(printf '\033[1;33m')
11+
RESET=$(printf '\033[0m')
12+
13+
# --- Skip flag ---
14+
if [ -n "${SKIP_OPTIMIZATIONS:-}" ]; then
15+
exit 0
16+
fi
17+
18+
# --- Helpers ---
19+
20+
get_sysctl() {
21+
sysctl -n "$1" 2>/dev/null || echo "unknown"
22+
}
23+
24+
set_sysctl_if_needed() {
25+
key="$1"
26+
expected="$2"
27+
28+
current="$(get_sysctl "$key")"
29+
30+
# Already correct
31+
if [ "$current" = "$expected" ]; then
32+
return 0
33+
fi
34+
35+
# Try to apply
36+
if sysctl -w "$key=$expected" >/dev/null 2>&1; then
37+
return 0
38+
fi
39+
40+
# Failed
41+
return 1
42+
}
43+
44+
# --- Apply Settings (best effort) ---
45+
46+
failed=0
47+
48+
set_sysctl_if_needed net.ipv4.conf.all.arp_ignore 1 || failed=1
49+
set_sysctl_if_needed net.ipv4.conf.all.arp_announce 2 || failed=1
50+
set_sysctl_if_needed net.ipv4.conf.default.arp_ignore 1 || failed=1
51+
set_sysctl_if_needed net.ipv4.conf.default.arp_announce 2 || failed=1
52+
53+
# --- Validate final state ---
54+
55+
all_ignore="$(get_sysctl net.ipv4.conf.all.arp_ignore)"
56+
all_announce="$(get_sysctl net.ipv4.conf.all.arp_announce)"
57+
58+
# --- Warning Output ---
59+
60+
if [ "$all_ignore" != "1" ] || [ "$all_announce" != "2" ]; then
61+
>&2 printf "%s" "${YELLOW}"
62+
>&2 cat <<EOF
63+
══════════════════════════════════════════════════════════════════════════════
64+
⚠️ ATTENTION: ARP flux protection not enabled.
65+
66+
NetAlertX relies on ARP for device detection. Your system currently allows
67+
ARP replies from incorrect interfaces (ARP flux), which may result in:
68+
69+
• False devices being detected
70+
• IP/MAC mismatches
71+
• Flapping device states
72+
• Incorrect network topology
73+
74+
This is common when running in Docker or multi-interface environments.
75+
76+
──────────────────────────────────────────────────────────────────────────
77+
Recommended fix (Docker Compose):
78+
79+
sysctls:
80+
net.ipv4.conf.all.arp_ignore: 1
81+
net.ipv4.conf.all.arp_announce: 2
82+
83+
──────────────────────────────────────────────────────────────────────────
84+
Alternatively, apply on the host:
85+
86+
net.ipv4.conf.all.arp_ignore=1
87+
net.ipv4.conf.all.arp_announce=2
88+
89+
Detection accuracy may be reduced until this is configured.
90+
══════════════════════════════════════════════════════════════════════════════
91+
EOF
92+
>&2 printf "%s" "${RESET}"
93+
fi

0 commit comments

Comments
 (0)