From 70a88f478996ac4ca214cb9d642724890f3b7cd1 Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Tue, 4 Sep 2018 20:26:40 +0800 Subject: [PATCH] redir: added `redir6` proxy --- README.md | 6 +++--- conf.go | 3 ++- main.go | 2 +- proxy/redir/redir_linux.go | 15 +++++++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e8a0ca6..7fed04f 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ DNS Forwarding Server (udp2tcp): - DNS cache - Custom dns record -IPSet Management: +IPSet Management (Linux kernel version >= 2.6.32): - Add ip/cidrs from rule files on startup - Add resolved ips for domains from rule files by dns forwarding server @@ -55,8 +55,8 @@ IPSet Management: General: - Http and socks5 on the same port -- Forward chain -- RR/HA/LHA strategy for multiple forwarders +- Forwarder chain +- RR/HA/LHA/DH strategy for multiple forwarders - Periodical proxy checking - Rule proxy based on destinations: [Config Examples](config/examples) - Send requests from specific ip/interface diff --git a/conf.go b/conf.go index 89ec134..edf498a 100644 --- a/conf.go +++ b/conf.go @@ -121,13 +121,14 @@ func usage() { fmt.Fprintf(os.Stderr, " tls: tls transport\n") fmt.Fprintf(os.Stderr, " ws: websocket transport\n") fmt.Fprintf(os.Stderr, " redir: redirect proxy. (used on linux as a transparent proxy with iptables redirect rules)\n") + fmt.Fprintf(os.Stderr, " redir6: redirect proxy(ipv6)\n") fmt.Fprintf(os.Stderr, " tcptun: tcp tunnel\n") fmt.Fprintf(os.Stderr, " udptun: udp tunnel\n") fmt.Fprintf(os.Stderr, " uottun: udp over tcp tunnel\n") fmt.Fprintf(os.Stderr, "\n") fmt.Fprintf(os.Stderr, "Available schemes for different modes:\n") - fmt.Fprintf(os.Stderr, " listen: mixed ss socks5 http redir tcptun udptun uottun\n") + fmt.Fprintf(os.Stderr, " listen: mixed ss socks5 http redir redir6 tcptun udptun uottun\n") fmt.Fprintf(os.Stderr, " forward: ss socks5 http ssr vmess tls ws\n") fmt.Fprintf(os.Stderr, "\n") diff --git a/main.go b/main.go index 0c26f61..8634a86 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ import ( ) // VERSION . -const VERSION = "0.6.8" +const VERSION = "0.6.9" func main() { // read configs diff --git a/proxy/redir/redir_linux.go b/proxy/redir/redir_linux.go index 1d202fc..3a808f8 100644 --- a/proxy/redir/redir_linux.go +++ b/proxy/redir/redir_linux.go @@ -27,14 +27,16 @@ const ( type RedirProxy struct { dialer proxy.Dialer addr string + ipv6 bool } func init() { proxy.RegisterServer("redir", NewRedirServer) + proxy.RegisterServer("redir6", NewRedirServer6) } // NewRedirProxy returns a redirect proxy. -func NewRedirProxy(s string, dialer proxy.Dialer) (*RedirProxy, error) { +func NewRedirProxy(s string, dialer proxy.Dialer, ipv6 bool) (*RedirProxy, error) { u, err := url.Parse(s) if err != nil { log.F("parse err: %s", err) @@ -45,6 +47,7 @@ func NewRedirProxy(s string, dialer proxy.Dialer) (*RedirProxy, error) { r := &RedirProxy{ dialer: dialer, addr: addr, + ipv6: ipv6, } return r, nil @@ -52,7 +55,12 @@ func NewRedirProxy(s string, dialer proxy.Dialer) (*RedirProxy, error) { // NewRedirServer returns a redir server. func NewRedirServer(s string, dialer proxy.Dialer) (proxy.Server, error) { - return NewRedirProxy(s, dialer) + return NewRedirProxy(s, dialer, false) +} + +// NewRedirServer returns a redir server. +func NewRedirServer6(s string, dialer proxy.Dialer) (proxy.Server, error) { + return NewRedirProxy(s, dialer, true) } // ListenAndServe . @@ -79,7 +87,7 @@ func (s *RedirProxy) ListenAndServe() { c.SetKeepAlive(true) } - tgt, err := getOrigDst(c, false) + tgt, err := getOrigDst(c, s.ipv6) if err != nil { log.F("[redir] failed to get target address: %v", err) return @@ -151,7 +159,6 @@ func getorigdst(fd uintptr) (socks.Addr, error) { } // Call ipv6_getorigdst() from linux/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c -// NOTE: I haven't tried yet but it should work since Linux 3.8. func getorigdstIPv6(fd uintptr) (socks.Addr, error) { raw := syscall.RawSockaddrInet6{} siz := unsafe.Sizeof(raw)