Skip to content

Commit

Permalink
cmd s5: multi fake dns support
Browse files Browse the repository at this point in the history
  • Loading branch information
rkonfj committed May 26, 2023
1 parent bb873ed commit cf263df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/s5/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
Cmd.Flags().String("dns", "", "local dns upstream (leave blank to disable local dns)")
Cmd.Flags().String("dns-listen", "127.0.0.1:2053", "local dns listen address")
Cmd.Flags().String("dns-evict", "2h", "local dns cache evict duration")
Cmd.Flags().String("dns-fake", "", "local fake dns (leave blank to disable fake dns)")
Cmd.Flags().StringSlice("dns-fake", []string{}, "local fake dns (leave blank to disable fake dns)")
}

func startAction(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -56,7 +56,7 @@ func processOptions(cmd *cobra.Command) (opts server.Options, err error) {
return
}

opts.DNSFake, err = cmd.Flags().GetString("dns-fake")
opts.DNSFake, err = cmd.Flags().GetStringSlice("dns-fake")
if err != nil {
return
}
Expand Down
14 changes: 9 additions & 5 deletions cmd/s5/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Options struct {
DataRoot string
// when using socks5 proxy dns query, if the query dns is consistent with the fake ip
// the query request will be processed by the built-in local dns
DNSFake string
DNSFake []string
// build-in local dns listen address
DNSListen string
// build-in local dns used upstream dns
Expand Down Expand Up @@ -235,10 +235,14 @@ func (s *S5Server) registerHTTPHandlers() {
func (s *S5Server) dial(ctx context.Context, addr, network string) (
dialerName string, conn net.Conn, err error) {
// dial localdns instead of fake dns
if len(s.opts.DNSFake) > 0 && len(s.opts.DNSUpstream) > 0 && strings.Contains(addr, s.opts.DNSFake) {
dialerName = "direct"
conn, err = s.defaultDialer.Dial(network, s.opts.DNSListen)
return
if len(s.opts.DNSFake) > 0 && len(s.opts.DNSUpstream) > 0 {
for _, fake := range s.opts.DNSFake {
if strings.Contains(addr, fake) {
dialerName = "direct"
conn, err = s.defaultDialer.Dial(network, s.opts.DNSListen)
return
}
}
}

host, port, err := net.SplitHostPort(addr)
Expand Down

0 comments on commit cf263df

Please sign in to comment.