-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
curl -fsS "https://cloudflare.com/cdn-cgi/trace" | grep -qE "warp=(plus|on)" || exit 1 | ||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
# exit when any command fails | ||
set -e | ||
|
||
interfaces=$(ip --json address | jq -r ' | ||
.[] | | ||
select(.ifname != "lo") | | ||
.ifname | ||
') | ||
|
||
# if CloudflareWARP not started, abort | ||
if [[ ! "$interfaces" =~ "CloudflareWARP" ]]; then | ||
echo "[fix-host-connectivity] CloudflareWARP not started, skip." | ||
exit 0 | ||
fi | ||
|
||
# get excluded networks | ||
networks=$(ip --json address | jq -r ' | ||
.[] | | ||
select((.ifname != "lo") and (.ifname != "CloudflareWARP")) | | ||
.addr_info[] | | ||
select(.family == "inet") | | ||
"\(.local)/\(.prefixlen)"' | | ||
xargs -I {} sh -c ' | ||
if echo {} | grep -q "/32$"; then | ||
echo {}; | ||
else | ||
ipcalc -n {} | grep Network | awk "{print \$2}"; | ||
fi | ||
') | ||
|
||
# if no networks found, abort | ||
if [ -z "$networks" ]; then | ||
echo "[fix-host-connectivity] WARNING: No networks found, abort." | ||
exit 0 | ||
fi | ||
|
||
# add excluded networks to nft table cloudflare-warp and routing table | ||
for network in $networks; do | ||
sudo nft add rule inet cloudflare-warp input ip saddr $network accept | ||
sudo nft add rule inet cloudflare-warp output ip daddr $network accept | ||
# stop packet from using routing table created by CloudflareWARP | ||
sudo ip rule add to $network lookup main priority 10 | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
# exit when any command fails | ||
set -e | ||
|
||
# get where the script is located | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
bash $DIR/connected-to-warp.sh | ||
|
||
# if BETA_FIX_HOST_CONNECTIVITY is set, run fix-host-connectivity.sh | ||
if [ -n "$BETA_FIX_HOST_CONNECTIVITY" ]; then | ||
bash $DIR/fix-host-connectivity.sh | ||
fi |