From 4ece9ece25b9060a276046f616b919469b36012d Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Fri, 8 Mar 2019 00:14:37 +0800 Subject: [PATCH] dns: allow to resolve domain which in a reject rule --- README.md | 1 + conf.go | 1 + dns/client.go | 4 +++- proxy/reject/reject.go | 6 +++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f499073..55f5dad 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/conf.go b/conf.go index 70bb0ff..abc9d4b 100644 --- a/conf.go +++ b/conf.go @@ -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") diff --git a/dns/client.go b/dns/client.go index 0bd49f4..71259aa 100644 --- a/dns/client.go +++ b/dns/client.go @@ -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" } diff --git a/proxy/reject/reject.go b/proxy/reject/reject.go index b210354..c511138 100644 --- a/proxy/reject/reject.go +++ b/proxy/reject/reject.go @@ -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") }