Created
August 18, 2023 10:38
-
-
Save majek/bc7cd3c897a2da2eb2280f870b5711d5 to your computer and use it in GitHub Desktop.
Manage `ip mptcp endpoint` state on linux
This file contains 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/bash | |
set -e | |
echo "[+] Clearling old mptcp endpoints" | |
for i in `ip mptcp endpoint show|cut -d " " -f 3`; do | |
ip mptcp endpoint delete id $i; | |
done | |
declare -A OLD | |
ID=1 | |
(echo YES; ip monitor address) | while read LINE; do | |
echo "[.] Update" | |
declare -A NEW | |
while read -r IFACE ADDR; do | |
L="$ADDR dev $IFACE" | |
if [ "${OLD[$L]}" == "" ] && [ "${NEW[$L]}" == "" ]; then | |
NEW["$L"]="$ID" | |
echo "ip mptcp endpoint add $L id $ID subflow" | |
ip mptcp endpoint add $L id $ID subflow | |
ID=$[$ID+1] | |
elif [ "${NEW[$L]}" != "" ]; then | |
NEW["$L"]="${OLD["$L"]}" | |
unset OLD["$L"] | |
# already there | |
fi | |
done <<< $(\ | |
ip -j address \ | |
| jq -r \ | |
".[] \ | |
| select( .operstate | contains(\"UP\") ) \ | |
| .ifname as \$ifname \ | |
| .addr_info[] \ | |
| select(.scope | contains(\"global\")) \ | |
| select(.temporary | . == null or . == \"\") \ | |
| \$ifname + \" \" + .local" \ | |
) | |
for OLDL in "${!OLD[@]}"; do | |
DID="${OLD["$OLDL"]}" | |
echo "ip mptcp endpoint delete id $DID # $OLDL" | |
ip mptcp endpoint delete id $DID | |
unset OLD["$OLDL"] | |
unset NEW["$OLDL"] | |
done | |
for L in "${!NEW[@]}"; do | |
OLD["$L"]="${NEW["$L"]}" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice script!
Note that you can replace the first
for
loop to remove the old MPTCP endpoints by: