Page MenuHomeDevCentral

D3651.diff
No OneTemporary

D3651.diff

diff --git a/utils/query-ndp-for-ipv6-neighbor.sh b/utils/query-ndp-for-ipv6-neighbor.sh
new file mode 100644
--- /dev/null
+++ b/utils/query-ndp-for-ipv6-neighbor.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+# shellcheck disable=SC2086
+
+# -------------------------------------------------------------
+# rOPS — determine IPv6 router with neighbor discovery protocol
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Read the output of `ndp -an` to find the first
+# IP address not matching one of the server MAC.
+# That should be a de facto gateway.
+# -------------------------------------------------------------
+
+set -e
+
+# -------------------------------------------------------------
+# Parse arguments
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+if [ -z "$1" ]; then
+ echo "Usage: $0 <interface>"
+ echo "Example: $0 igb0"
+ exit 1
+fi
+
+IFACE="$1"
+
+# -------------------------------------------------------------
+# Collect local MAC addresses
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+LOCAL_MACS=$(ifconfig "$IFACE" | while read -r line; do
+ case "$line" in
+ *ether*) set -- $line; echo "$2";;
+ esac
+done)
+
+LOCAL_MACS_STR=""
+for m in $LOCAL_MACS; do
+ LOCAL_MACS_STR="$LOCAL_MACS_STR $m"
+done
+
+# -------------------------------------------------------------
+# Parse ndp -an output
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+skip=1
+ndp -an | while read -r ipv mac rest; do
+ # Skip header or incomplete entrie
+ if [ $skip -eq 1 ]; then skip=0; continue; fi
+ [ "$mac" = "(incomplete)" ] && continue
+
+ # Skip local MACs
+ found=0
+ for m in $LOCAL_MACS_STR; do
+ [ "$mac" = "$m" ] && found=1 && break
+ done
+ [ $found -eq 1 ] && continue
+
+ # We've got a winner!
+ case "$ipv" in
+ *%*) ipv=${ipv%%%*} ;;
+ esac
+
+ echo "$ipv"
+ break
+done

File Metadata

Mime Type
text/plain
Expires
Thu, Sep 4, 02:37 (6 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2955158
Default Alt Text
D3651.diff (2 KB)

Event Timeline