Skip to content

Commit

Permalink
move LD_PRELOADs to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
grische committed Mar 15, 2024
1 parent 6092615 commit 8208b62
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ resolve_host() {
fi
}

force_wan_connection() {
LD_PRELOAD=libpacketmark.so LIBPACKETMARK_MARK=1 gluon-wan "$@"
}

# Do we already have a private-key? If not generate one
if ! uci -q get wireguard.mesh_vpn.privatekey > /dev/null
then
Expand Down Expand Up @@ -102,7 +106,7 @@ if [ "$(uci get wireguard.mesh_vpn.enabled)" = "true" ] || [ "$(uci get wireguar
fi
done
# shellcheck disable=SC2086 # otherwise ntpd cries
if ! LD_PRELOAD=libpacketmark.so LIBPACKETMARK_MARK=1 gluon-wan /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug ${NTP_SERVERS_ADDRS} -q
if ! force_wan_connection /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug ${NTP_SERVERS_ADDRS} -q
then
logger -p err -t checkuplink "Unable to establish NTP connection to ${NTP_SERVERS}."
exit 3
Expand Down Expand Up @@ -136,7 +140,7 @@ if [ "$(uci get wireguard.mesh_vpn.enabled)" = "true" ] || [ "$(uci get wireguar
# Use /api/v2, get gateway peer details from broker response
WGKEX_BROKER="$PROTO://$WGKEX_BROKER_BASE_PATH/api/v2/wg/key/exchange"
logger -t checkuplink "Contacting wgkex broker $WGKEX_BROKER"
if ! WGKEX_DATA=$(LD_PRELOAD=libpacketmark.so LIBPACKETMARK_MARK=1 gluon-wan wget -q -O- --post-data='{"domain": "'"$SEGMENT"'","public_key": "'"$PUBLICKEY"'"}' "$WGKEX_BROKER"); then
if ! WGKEX_DATA=$(force_wan_connection wget -q -O- --post-data='{"domain": "'"$SEGMENT"'","public_key": "'"$PUBLICKEY"'"}' "$WGKEX_BROKER"); then
logger -p err -t checkuplink "Contacting wgkex broker failed, response: $WGKEX_DATA"
exit 1
fi
Expand All @@ -163,7 +167,7 @@ if [ "$(uci get wireguard.mesh_vpn.enabled)" = "true" ] || [ "$(uci get wireguar
# Use /api/v1, get gateway peer details from config
WGKEX_BROKER="$PROTO://$WGKEX_BROKER_BASE_PATH/api/v1/wg/key/exchange"
logger -p info -t checkuplink "Contacting wgkex broker $WGKEX_BROKER"
if ! LD_PRELOAD=libpacketmark.so LIBPACKETMARK_MARK=1 gluon-wan wget -q -O- --post-data='{"domain": "'"$SEGMENT"'","public_key": "'"$PUBLICKEY"'"}' "$WGKEX_BROKER"; then
if ! force_wan_connection wget -q -O- --post-data='{"domain": "'"$SEGMENT"'","public_key": "'"$PUBLICKEY"'"}' "$WGKEX_BROKER"; then
logger -p err -t checkuplink "Contacting wgkex broker failed"
exit 1
fi
Expand Down

0 comments on commit 8208b62

Please sign in to comment.