dns: allow to resolve domain which in a reject rule

This commit is contained in:
nadoo 2019-03-08 00:14:37 +08:00
parent 2e44d79db8
commit 4ece9ece25
4 changed files with 8 additions and 4 deletions

View File

@ -171,6 +171,7 @@ Available Schemes:
unix: unix domain socket
kcp: kcp protocol
simple-obfs: simple-obfs protocol
reject: a virtual proxy which just reject connections
Available schemes for different modes:
listen: mixed ss socks5 http redir redir6 tcptun udptun uottun tls unix kcp

View File

@ -123,6 +123,7 @@ func usage() {
fmt.Fprintf(os.Stderr, " unix: unix domain socket\n")
fmt.Fprintf(os.Stderr, " kcp: kcp protocol\n")
fmt.Fprintf(os.Stderr, " simple-obfs: simple-obfs protocol\n")
fmt.Fprintf(os.Stderr, " reject: a virtual proxy which just reject connections\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Available schemes for different modes:\n")

View File

@ -129,11 +129,13 @@ func (c *Client) exchange(qname string, reqBytes []byte, preferTCP bool) (server
dialer := c.dialer.NextDialer(qname + ":53")
// if we are resolving the dialer's domain, then use Direct to avoid denpency loop
if strings.Contains(dialer.Addr(), qname) {
// TODO: dialer.Addr() == "reject", tricky
if strings.Contains(dialer.Addr(), qname) || dialer.Addr() == "REJECT" {
dialer = proxy.Default
}
// If client uses udp and no forwarders specified, use udp
// TODO: dialer.Addr() == "DIRECT", tricky
if !preferTCP && !c.config.AlwaysTCP && dialer.Addr() == "DIRECT" {
network = "udp"
}

View File

@ -26,15 +26,15 @@ func NewRejectDialer(s string, dialer proxy.Dialer) (proxy.Dialer, error) {
}
// Addr returns forwarder's address.
func (s *Reject) Addr() string { return "reject" }
func (s *Reject) Addr() string { return "REJECT" }
// NextDialer returns the next dialer.
func (s *Reject) NextDialer(dstAddr string) proxy.Dialer { return s }
// Dial connects to the address addr on the network net via the proxy.
func (s *Reject) Dial(network, addr string) (net.Conn, error) { return nil, errors.New("reject") }
func (s *Reject) Dial(network, addr string) (net.Conn, error) { return nil, errors.New("REJECT") }
// DialUDP connects to the given address via the proxy.
func (s *Reject) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
return nil, nil, errors.New("reject")
return nil, nil, errors.New("REJECT")
}