small-package/luci-app-xray/root/etc/hotplug.d/iface/01-transparent-proxy-ipset.fw4

19 lines
724 B
Bash

#!/bin/sh
if [ ! -s /usr/share/xray/ignore_tp_spec_def_gw ] ; then
DEFAULT_GATEWAY=$(ip route get 1.1.1.1 | grep -Eoe "src (\d+.\d+.\d+.\d+)" | awk '{print $NF}')
if [ -n "$DEFAULT_GATEWAY" ] ; then
logger -st transparent-proxy-ipset[$$] -p6 "default gateway available at $DEFAULT_GATEWAY"
nft -f - <<-EOF
add set inet fw4 tp_spec_def_gw { type ipv4_addr; }
flush set inet fw4 tp_spec_def_gw
add element inet fw4 tp_spec_def_gw { $DEFAULT_GATEWAY }
EOF
else
logger -st transparent-proxy-ipset[$$] -p6 "default gateway not available, please wait for interface ready"
fi
fi
if [ -s /usr/share/xray/restart_dnsmasq_on_iface_change ] ; then
service dnsmasq restart
fi