mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
redir: added redir6
proxy
This commit is contained in:
parent
4e5ee78df9
commit
70a88f4789
@ -47,7 +47,7 @@ DNS Forwarding Server (udp2tcp):
|
|||||||
- DNS cache
|
- DNS cache
|
||||||
- Custom dns record
|
- Custom dns record
|
||||||
|
|
||||||
IPSet Management:
|
IPSet Management (Linux kernel version >= 2.6.32):
|
||||||
|
|
||||||
- Add ip/cidrs from rule files on startup
|
- Add ip/cidrs from rule files on startup
|
||||||
- Add resolved ips for domains from rule files by dns forwarding server
|
- Add resolved ips for domains from rule files by dns forwarding server
|
||||||
@ -55,8 +55,8 @@ IPSet Management:
|
|||||||
General:
|
General:
|
||||||
|
|
||||||
- Http and socks5 on the same port
|
- Http and socks5 on the same port
|
||||||
- Forward chain
|
- Forwarder chain
|
||||||
- RR/HA/LHA strategy for multiple forwarders
|
- RR/HA/LHA/DH strategy for multiple forwarders
|
||||||
- Periodical proxy checking
|
- Periodical proxy checking
|
||||||
- Rule proxy based on destinations: [Config Examples](config/examples)
|
- Rule proxy based on destinations: [Config Examples](config/examples)
|
||||||
- Send requests from specific ip/interface
|
- Send requests from specific ip/interface
|
||||||
|
3
conf.go
3
conf.go
@ -121,13 +121,14 @@ func usage() {
|
|||||||
fmt.Fprintf(os.Stderr, " tls: tls transport\n")
|
fmt.Fprintf(os.Stderr, " tls: tls transport\n")
|
||||||
fmt.Fprintf(os.Stderr, " ws: websocket 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, " 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, " tcptun: tcp tunnel\n")
|
||||||
fmt.Fprintf(os.Stderr, " udptun: udp tunnel\n")
|
fmt.Fprintf(os.Stderr, " udptun: udp tunnel\n")
|
||||||
fmt.Fprintf(os.Stderr, " uottun: udp over tcp tunnel\n")
|
fmt.Fprintf(os.Stderr, " uottun: udp over tcp tunnel\n")
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "Available schemes for different modes:\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, " forward: ss socks5 http ssr vmess tls ws\n")
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
|
|
||||||
|
2
main.go
2
main.go
@ -27,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// VERSION .
|
// VERSION .
|
||||||
const VERSION = "0.6.8"
|
const VERSION = "0.6.9"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// read configs
|
// read configs
|
||||||
|
@ -27,14 +27,16 @@ const (
|
|||||||
type RedirProxy struct {
|
type RedirProxy struct {
|
||||||
dialer proxy.Dialer
|
dialer proxy.Dialer
|
||||||
addr string
|
addr string
|
||||||
|
ipv6 bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proxy.RegisterServer("redir", NewRedirServer)
|
proxy.RegisterServer("redir", NewRedirServer)
|
||||||
|
proxy.RegisterServer("redir6", NewRedirServer6)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRedirProxy returns a redirect proxy.
|
// 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)
|
u, err := url.Parse(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.F("parse err: %s", err)
|
log.F("parse err: %s", err)
|
||||||
@ -45,6 +47,7 @@ func NewRedirProxy(s string, dialer proxy.Dialer) (*RedirProxy, error) {
|
|||||||
r := &RedirProxy{
|
r := &RedirProxy{
|
||||||
dialer: dialer,
|
dialer: dialer,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
ipv6: ipv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
@ -52,7 +55,12 @@ func NewRedirProxy(s string, dialer proxy.Dialer) (*RedirProxy, error) {
|
|||||||
|
|
||||||
// NewRedirServer returns a redir server.
|
// NewRedirServer returns a redir server.
|
||||||
func NewRedirServer(s string, dialer proxy.Dialer) (proxy.Server, error) {
|
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 .
|
// ListenAndServe .
|
||||||
@ -79,7 +87,7 @@ func (s *RedirProxy) ListenAndServe() {
|
|||||||
c.SetKeepAlive(true)
|
c.SetKeepAlive(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
tgt, err := getOrigDst(c, false)
|
tgt, err := getOrigDst(c, s.ipv6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.F("[redir] failed to get target address: %v", err)
|
log.F("[redir] failed to get target address: %v", err)
|
||||||
return
|
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
|
// 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) {
|
func getorigdstIPv6(fd uintptr) (socks.Addr, error) {
|
||||||
raw := syscall.RawSockaddrInet6{}
|
raw := syscall.RawSockaddrInet6{}
|
||||||
siz := unsafe.Sizeof(raw)
|
siz := unsafe.Sizeof(raw)
|
||||||
|
Loading…
Reference in New Issue
Block a user