mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 15:52:38 +08:00 
			
		
		
		
	uottun: support local udp 2 udp forwarding when there are no remote forwarders
This commit is contained in:
		
							parent
							
								
									4fb3718381
								
							
						
					
					
						commit
						775e3c05de
					
				@ -48,7 +48,8 @@ General:
 | 
			
		||||
 | 
			
		||||
TODO:
 | 
			
		||||
- [x] UDP over TCP Tunnel (client <--udp--> glider/uottun <--tcp--> ss <--udp--> target)
 | 
			
		||||
- [ ] Transparent UDP proxy (linux tproxy)
 | 
			
		||||
- [ ] Transparent UDP proxy (iptables tproxy)
 | 
			
		||||
- [ ] DNS Cache
 | 
			
		||||
- [ ] TUN/TAP device support
 | 
			
		||||
- [ ] Code refactoring: support proxy registering so it can be pluggable
 | 
			
		||||
- [ ] Conditional compilation so we can abandon needless proxy type and get a smaller binary size
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								dns.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								dns.go
									
									
									
									
									
								
							@ -279,6 +279,7 @@ func (s *DNS) ServeTCP(c net.Conn) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Exchange handles request msg and returns response msg
 | 
			
		||||
// TODO: multiple questions support, parse header to get the number of questions
 | 
			
		||||
func (s *DNS) Exchange(reqLen uint16, reqMsg []byte, addr string) (respLen uint16, respMsg []byte, err error) {
 | 
			
		||||
	// fmt.Printf("\ndns req len %d:\n%s\n", reqLen, hex.Dump(reqMsg[:]))
 | 
			
		||||
	query, err := parseQuestion(reqMsg)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								ss.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								ss.go
									
									
									
									
									
								
							@ -209,7 +209,6 @@ func (s *SS) ListenAndServeUDP() {
 | 
			
		||||
 | 
			
		||||
// Dial connects to the address addr on the network net via the proxy.
 | 
			
		||||
func (s *SS) Dial(network, addr string) (net.Conn, error) {
 | 
			
		||||
 | 
			
		||||
	target := ParseAddr(addr)
 | 
			
		||||
	if target == nil {
 | 
			
		||||
		return nil, errors.New("Unable to parse address: " + addr)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								uottun.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								uottun.go
									
									
									
									
									
								
							@ -3,6 +3,7 @@ package main
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"net"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// UoTTun udp over tcp tunnel
 | 
			
		||||
@ -26,7 +27,6 @@ func NewUoTTun(addr, raddr string, sDialer Dialer) (*UoTTun, error) {
 | 
			
		||||
 | 
			
		||||
// ListenAndServe .
 | 
			
		||||
func (s *UoTTun) ListenAndServe() {
 | 
			
		||||
 | 
			
		||||
	c, err := net.ListenPacket("udp", s.addr)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logf("proxy-uottun failed to listen on %s: %v", s.addr, err)
 | 
			
		||||
@ -55,14 +55,21 @@ func (s *UoTTun) ListenAndServe() {
 | 
			
		||||
 | 
			
		||||
			rc.Write(buf[:n])
 | 
			
		||||
 | 
			
		||||
			// no remote forwarder
 | 
			
		||||
			if urc, ok := rc.(*net.UDPConn); ok {
 | 
			
		||||
				go func() {
 | 
			
		||||
					timedCopy(c, clientAddr, urc, 5*time.Minute, false)
 | 
			
		||||
					urc.Close()
 | 
			
		||||
				}()
 | 
			
		||||
			} else { // remote forwarder, udp over tcp
 | 
			
		||||
				resp, err := ioutil.ReadAll(rc)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					logf("error in ioutil.ReadAll: %s\n", err)
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
				rc.Close()
 | 
			
		||||
 | 
			
		||||
				c.WriteTo(resp, clientAddr)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			logf("proxy-uottun %s <-> %s", clientAddr, s.raddr)
 | 
			
		||||
		}()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user