support multiple network interfaces
This commit is contained in:
@ -51,11 +51,6 @@ func (d *sshdDialer) Multiplex() bool {
|
||||
}
|
||||
|
||||
func (d *sshdDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialOption) (conn net.Conn, err error) {
|
||||
var options dialer.DialOptions
|
||||
for _, opt := range opts {
|
||||
opt(&options)
|
||||
}
|
||||
|
||||
d.sessionMutex.Lock()
|
||||
defer d.sessionMutex.Unlock()
|
||||
|
||||
@ -65,7 +60,16 @@ func (d *sshdDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
|
||||
ok = false
|
||||
}
|
||||
if !ok {
|
||||
conn, err = d.dial(ctx, "tcp", addr, &options)
|
||||
var options dialer.DialOptions
|
||||
for _, opt := range opts {
|
||||
opt(&options)
|
||||
}
|
||||
|
||||
netd := options.NetDialer
|
||||
if netd == nil {
|
||||
netd = dialer.DefaultNetDialer
|
||||
}
|
||||
conn, err = netd.Dial(ctx, "tcp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -129,36 +133,6 @@ func (d *sshdDialer) Handshake(ctx context.Context, conn net.Conn, options ...di
|
||||
return ssh_util.NewClientConn(session.conn, session.client), nil
|
||||
}
|
||||
|
||||
func (d *sshdDialer) dial(ctx context.Context, network, addr string, opts *dialer.DialOptions) (net.Conn, error) {
|
||||
log := d.options.Logger
|
||||
|
||||
dial := opts.DialFunc
|
||||
if dial != nil {
|
||||
conn, err := dial(ctx, addr)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
} else {
|
||||
log.WithFields(map[string]any{
|
||||
"src": conn.LocalAddr().String(),
|
||||
"dst": addr,
|
||||
}).Debug("dial with dial func")
|
||||
}
|
||||
return conn, err
|
||||
}
|
||||
|
||||
var netd net.Dialer
|
||||
conn, err := netd.DialContext(ctx, network, addr)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
} else {
|
||||
log.WithFields(map[string]any{
|
||||
"src": conn.LocalAddr().String(),
|
||||
"dst": addr,
|
||||
}).Debugf("dial direct %s/%s", addr, network)
|
||||
}
|
||||
return conn, err
|
||||
}
|
||||
|
||||
func (d *sshdDialer) initSession(ctx context.Context, addr string, conn net.Conn) (*sshSession, error) {
|
||||
config := ssh.ClientConfig{
|
||||
// Timeout: timeout,
|
||||
|
Reference in New Issue
Block a user