Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add socket options to fd #5270

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/protocols/common/protocolstate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"fmt"
"net"
"net/url"
"syscall"

"github.com/go-sql-driver/mysql"
"github.com/pkg/errors"
"golang.org/x/net/proxy"
"golang.org/x/sys/unix"

"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/mapcidr/asn"
Expand Down Expand Up @@ -135,6 +137,31 @@
// this instance is used in javascript protocol libraries and
// dial history is required to get dialed ip of a host
opts.WithDialerHistory = true
opts.Dialer = &net.Dialer{
Timeout: opts.DialerTimeout,
KeepAlive: opts.DialerKeepAlive,
DualStack: true,
ControlContext: func(ctx context.Context, network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
err := syscall.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_KEEPALIVE, 1)

Check failure on line 146 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

cannot use int(fd) (value of type int) as syscall.Handle value in argument to syscall.SetsockoptInt

Check failure on line 146 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

undefined: unix.SOL_SOCKET

Check failure on line 146 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

undefined: unix.SO_KEEPALIVE
if err != nil {
fmt.Printf("error setting SO_KEEPALIVE: %v\n", err)
}
tv := syscall.Timeval{
Sec: 5,
}
if err := syscall.SetsockoptTimeval(int(fd), unix.SOL_SOCKET, unix.SO_RCVTIMEO, &tv); err != nil {

Check failure on line 153 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

cannot use int(fd) (value of type int) as syscall.Handle value in argument to syscall.SetsockoptTimeval

Check failure on line 153 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

undefined: unix.SOL_SOCKET

Check failure on line 153 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

undefined: unix.SO_RCVTIMEO
fmt.Printf("error setting SO_RCVTIMEO: %v tv: %v\n", err, tv)
}
tv2 := syscall.Timeval{
Sec: 5,
}
if err := syscall.SetsockoptTimeval(int(fd), unix.SOL_SOCKET, unix.SO_SNDTIMEO, &tv2); err != nil {

Check failure on line 159 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

cannot use int(fd) (value of type int) as syscall.Handle value in argument to syscall.SetsockoptTimeval

Check failure on line 159 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

undefined: unix.SOL_SOCKET

Check failure on line 159 in pkg/protocols/common/protocolstate/state.go

View workflow job for this annotation

GitHub Actions / release-test

undefined: unix.SO_SNDTIMEO
fmt.Printf("error setting SO_SNDTIMEO: %v tv: %v\n", err, tv2)
}
})
},
}

// fastdialer now by default fallbacks to ztls when there are tls related errors
dialer, err := fastdialer.NewDialer(opts)
Expand Down
Loading