diff --git a/README.md b/README.md index e16be36..2c0f799 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dns.go b/dns.go index ed9b05c..6ee4773 100644 --- a/dns.go +++ b/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) diff --git a/ss.go b/ss.go index 68fb7f0..fba69f7 100644 --- a/ss.go +++ b/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) diff --git a/uottun.go b/uottun.go index 62e6247..97abd28 100644 --- a/uottun.go +++ b/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]) - resp, err := ioutil.ReadAll(rc) - if err != nil { - logf("error in ioutil.ReadAll: %s\n", err) - return + // 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) } - rc.Close() - - c.WriteTo(resp, clientAddr) logf("proxy-uottun %s <-> %s", clientAddr, s.raddr) }()