Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11629298
D3651.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D3651.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D3651: Allow to discover IPv6 gateway for Online servers
Attached
Detach File
Event Timeline
Log In to Comment