Skip to content

Commit

Permalink
Pull request 258: 5874-openwrt-setsockopt
Browse files Browse the repository at this point in the history
Merge in GO/dnsproxy from 5874-openwrt-setsockopt to master

Squashed commit of the following:

commit 8897679
Author: Ainar Garipov <[email protected]>
Date:   Thu Jun 8 12:27:17 2023 +0300

    netutil: warn about setsockopt fail
  • Loading branch information
ainar-g committed Jun 8, 2023
1 parent af10111 commit 20fd473
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/netutil/listenconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import "net"
//
// TODO(a.garipov): Add tests.
//
// TODO(a.garipov): Add an option to not set SO_REUSEPORT on Unix to prevent
// issues with OpenWrt.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/5872.
//
// TODO(a.garipov): DRY with AdGuard DNS when we can.
func ListenConfig() (lc *net.ListenConfig) {
return &net.ListenConfig{
Expand Down
10 changes: 9 additions & 1 deletion internal/netutil/listenconfig_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"syscall"

"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/sys/unix"
)

Expand All @@ -25,7 +26,14 @@ func defaultListenControl(_, _ string, c syscall.RawConn) (err error) {

opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
if opErr != nil {
opErr = fmt.Errorf("setting SO_REUSEPORT: %w", opErr)
if errors.Is(opErr, unix.ENOPROTOOPT) {
// Some Linux OSs do not seem to support SO_REUSEPORT, including
// some varieties of OpenWrt. Issue a warning.
log.Info("warning: SO_REUSEPORT not supported: %s", opErr)
opErr = nil
} else {
opErr = fmt.Errorf("setting SO_REUSEPORT: %w", opErr)
}
}
})

Expand Down

0 comments on commit 20fd473

Please sign in to comment.