Last active
June 5, 2025 01:35
-
-
Save gomasy/afbed8a81c1e779298df12e7f1416231 to your computer and use it in GitHub Desktop.
NDProxy and prefix translation service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SRC_IF=$1 | |
SRC_PREFIX=$2 | |
DST_IF=$3 | |
DST_PREFIX=$4 | |
DST_IF_IP=$(ifconfig $DST_IF | grep $4 | awk '{print $2}') | |
# インターフェイスの ND Proxy を有効にする | |
sysctl net.ipv6.conf.$1.proxy_ndp=1 &> /dev/null | |
while true; do | |
PROXIED=$(ip -6 neigh show proxy dev $SRC_IF | grep $2 | awk '{print $1}' | sort) | |
CANDIDATE=$(ip -6 neigh show dev $DST_IF | grep $4 | awk '{print $1}' | sed "s/$4/$2/g" | sort) | |
MAC_ADDR=$(ip -6 neigh show dev $DST_IF | awk '{print $3}' | uniq | sort) | |
# ND を定期的に送って強制的に ULA を解決する | |
for mac in $MAC_ADDR; do | |
LL=$(ip -6 neigh show dev $DST_IF | grep fe80: | awk '{print $1}') | |
for ll in $LL; do | |
ndisc6 -s $DST_IF_IP $ll $DST_IF &> /dev/null | |
done | |
done | |
touch /tmp/ndproxy_src_ip | |
for proxy in $PROXIED; do | |
echo $proxy >> /tmp/ndproxy_src_ip | |
done | |
touch /tmp/ndproxy_dst_ip | |
for candidate in $CANDIDATE; do | |
echo $candidate >> /tmp/ndproxy_dst_ip | |
done | |
diff --old-line-format='' --unchanged-line-format='' --new-line-format='%L' /tmp/ndproxy_src_ip /tmp/ndproxy_dst_ip | xargs -i sh -c "echo New address added: {} && ip -6 neigh add proxy {} dev $SRC_IF" | |
diff --old-line-format='%L' --unchanged-line-format='' --new-line-format='' /tmp/ndproxy_src_ip /tmp/ndproxy_dst_ip | xargs -i sh -c "echo Staled address deleted: {} && ip -6 neigh del proxy {} dev $SRC_IF" | |
rm /tmp/ndproxy_* | |
sleep 3 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment