// OnUdpStart
// This script is executed when a, UDP port is opened.

// $listeningPort is the port you specified in "ports" list
// $redirectPort is assigned at runtime when the udp server is started. First port start at 9501 and is incremented for each server
// $isForward : true if is just port forwarding. False if it's reverse tethering
// $isSocks5 : if reverse tethering, indicate if socks5 must be used.
// all theses variables are read only

$LogI --------- Script : Udp port start : $listeningPort / $redirectPort

if $isForward  then
   return
fi

if $isAtRunTime then 
   return
fi

// reverse tethering
// send specific tcp port (53,...) to TETHER chain

if $isSocks5 = false then
   // send udp connection directly to the tunnel (42010+)
   $iptables -t nat -A TETHER -o $myInterface -p udp --dport $listeningPort -j REDIRECT --to $redirectPort  
else
   // Socks5 mode : redirection is done on redsocks client port : 42001
   // redsocks (42001) will communicate with Socks5Server (port 42003) that return the UdpRelay (42004)
   $iptables -t nat -A TETHER -o $myInterface -p udp --dport $listeningPort -j REDIRECT --to 42001
fi





