Skip to content

Commit

Permalink
Fix ssh outbound
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 3, 2024
1 parent 14447c8 commit 94ddda3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions protocol/ssh/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/base64"
"github.com/sagernet/sing/service"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -36,6 +37,7 @@ type Outbound struct {
outbound.Adapter
ctx context.Context
logger logger.ContextLogger
dnsRouter adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Build

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Build

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.21)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.22)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.20)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-arm64, freebsd, arm64)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (darwin-arm64, darwin, arm64)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-386, freebsd, 386)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv7, linux, arm, 7)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv5, linux, arm, 5)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64, darwin, amd64, v1)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-386, linux, 386)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64, freebsd, amd64, v1)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64, linux, mips64)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv6, linux, arm, 6)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64-v3, linux, amd64, v3)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64, linux, amd64, v1)

undefined: adapter.DNSRouter

Check failure on line 40 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-arm64, linux, arm64)

undefined: adapter.DNSRouter
dialer N.Dialer
serverAddr M.Socksaddr
user string
Expand All @@ -57,6 +59,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeSSH, tag, []string{N.NetworkTCP}, options.DialerOptions),
ctx: ctx,
logger: logger,
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Build

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Build

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.21)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.22)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.20)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-arm64, freebsd, arm64)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (darwin-arm64, darwin, arm64)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-386, freebsd, 386)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv7, linux, arm, 7)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv5, linux, arm, 5)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64, darwin, amd64, v1)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-386, linux, 386)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64, freebsd, amd64, v1)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64, linux, mips64)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv6, linux, arm, 6)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64-v3, linux, amd64, v3)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64, linux, amd64, v1)

undefined: adapter.DNSRouter

Check failure on line 62 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-arm64, linux, arm64)

undefined: adapter.DNSRouter
dialer: outboundDialer,
serverAddr: options.ServerOptions.Build(),
user: options.User,
Expand Down Expand Up @@ -187,6 +190,15 @@ func (s *Outbound) Close() error {
}

func (s *Outbound) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
if destination.IsFqdn() {
destinationAddresses, err := s.dnsRouter.Lookup(ctx, destination.Fqdn, adapter.DNSQueryOptions{})

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Build

undefined: adapter.DNSQueryOptions (typecheck)

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Build

undefined: adapter.DNSQueryOptions) (typecheck)

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.21)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.22)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.20)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-arm64, freebsd, arm64)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (darwin-arm64, darwin, arm64)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-386, freebsd, 386)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv7, linux, arm, 7)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv5, linux, arm, 5)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64, darwin, amd64, v1)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-386, linux, 386)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64, freebsd, amd64, v1)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64, linux, mips64)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv6, linux, arm, 6)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64-v3, linux, amd64, v3)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64, linux, amd64, v1)

undefined: adapter.DNSQueryOptions

Check failure on line 194 in protocol/ssh/outbound.go

View workflow job for this annotation

GitHub Actions / cross (linux-arm64, linux, arm64)

undefined: adapter.DNSQueryOptions
if err != nil {
return nil, err
}
destination = M.SocksaddrFrom(destinationAddresses[0], destination.Port)
} else if !destination.Addr.IsValid() {
return nil, E.New("invalid destination: ", destination)
}
client, err := s.connect()
if err != nil {
return nil, err
Expand Down

0 comments on commit 94ddda3

Please sign in to comment.