github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/scripts/openwrt/tproxy (about) 1 #!/bin/sh /etc/rc.common 2 # Copyright (C) 2007-2012 OpenWrt.org 3 4 START=99 5 6 USE_PROCD=1 7 PROG=${HOME}/yuhaiin_mipsle 8 9 HOST=${HOST:-0.0.0.0:50051} 10 CONFIG_PATH=${YUHAIIN_CONFIG_PATH:-${HOME}/yuhaiin} 11 CONFIG_FILE=${CONFIG_PATH}/config.json 12 13 TPROXY_PORT=$(jq -r '(.server.servers.tproxy.tproxy.host) | split(":")[1]' ${CONFIG_FILE}) 14 TPROXY_PORT=${TPROXY_PORT:-8083} 15 16 TABLE=${TABLE:-233} 17 LAN_IPS=${LAN_IPS:-"192.168.2.145 192.168.122.27"} 18 19 20 clear() { 21 iptables -t mangle -D PREROUTING -j YUHAAIN_TPROXY 22 #iptables -t mangle -D OUTPUT -j YUHAAIN_TPROXY_OUTPUT 23 24 iptables -t mangle -F YUHAAIN_TPROXY 25 #iptables -t mangle -F YUHAAIN_TPROXY_OUTPUT 26 iptables -t mangle -X YUHAAIN_TPROXY 27 #iptables -t mangle -X YUHAAIN_TPROXY_OUTPUT 28 29 ip rule del fwmark 1 table 100 30 ip route del local 0.0.0.0/0 dev lo table 100 31 } 32 33 start_service() { 34 procd_open_instance yuhaiin 35 procd_set_param command $PROG -host $HOST -path $CONFIG_PATH 36 procd_set_param stdout 1 37 procd_set_param stderr 1 38 39 clear 40 41 ip rule add fwmark 1 table 100 42 ip route add local 0.0.0.0/0 dev lo table 100 43 44 iptables -t mangle -N YUHAAIN_TPROXY 45 iptables -t mangle -A YUHAAIN_TPROXY -d 224.0.0.0/4 -j RETURN 46 iptables -t mangle -A YUHAAIN_TPROXY -d 255.255.255.255/32 -j RETURN 47 iptables -t mangle -A YUHAAIN_TPROXY -d 172.16.0.0/16 -j RETURN 48 iptables -t mangle -A YUHAAIN_TPROXY -d 127.0.0.1/32 -j RETURN 49 for addr in ${LAN_IPS}; do 50 logger "add lan $addr" 51 iptables -t mangle -A YUHAAIN_TPROXY -p tcp -s ${addr} -j TPROXY --on-port ${TPROXY_PORT} --tproxy-mark 1 52 iptables -t mangle -A YUHAAIN_TPROXY -p udp -s ${addr} -j TPROXY --on-port ${TPROXY_PORT} --tproxy-mark 1 53 done 54 55 56 # iptables -t mangle -N YUHAAIN_TPROXY_OUTPUT 57 # iptables -t mangle -A YUHAAIN_TPROXY_OUTPUT -d 224.0.0.0/4 -j RETURN 58 # iptables -t mangle -A YUHAAIN_TPROXY_OUTPUT -d 255.255.255.255/32 -j RETURN 59 # iptables -t mangle -A YUHAAIN_TPROXY_OUTPUT -d 172.16.0.0/16 -j RETURN 60 # iptables -t mangle -A YUHAAIN_TPROXY_OUTPUT -d 127.0.0.1/32 -j RETURN 61 # iptables -t mangle -A YUHAAIN_TPROXY_OUTPUT -p tcp -d 1.1.1.1 --dport 443 -j MARK --set-mark 1 62 # iptables -t mangle -A YUHAAIN_TPROXY_OUTPUT -p udp -d 1.1.1.1 --dport 53 -j MARK --set-mark 1 63 64 65 iptables -t mangle -A PREROUTING -j YUHAAIN_TPROXY 66 # iptables -t mangle -A OUTPUT -j YUHAAIN_TPROXY_OUTPUT 67 procd_close_instance 68 } 69 70 stop_service() { 71 procd_send_signal $PROG 72 73 clear 74 } 75 76 restart_service() { 77 stop 78 start 79 }