mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 09:25:41 +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
|
||||
- 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
|
||||
|
3
conf.go
3
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")
|
||||
|
||||
|
2
main.go
2
main.go
@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// VERSION .
|
||||
const VERSION = "0.6.8"
|
||||
const VERSION = "0.6.9"
|
||||
|
||||
func main() {
|
||||
// read configs
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user