forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge in DNS/adguard-home from 3444-dhcp-again to master Closes AdguardTeam#3444. Squashed commit of the following: commit 5459ded Merge: d655909 8e667d3 Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Aug 16 15:35:30 2021 +0300 Merge branch 'master' into 3444-dhcp-again commit d655909 Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Aug 16 15:28:38 2021 +0300 aghnet: fix linux commit 262f729 Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Aug 16 14:30:09 2021 +0300 aghnet: rm debug commit c54b107 Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Aug 16 14:21:07 2021 +0300 aghnet: imp bsd compat, fix openbsd static ip commit f9871a4 Author: Eugene Burkov <e.burkov@adguard.com> Date: Sat Aug 14 00:17:46 2021 +0300 aghnet: setsockopt
- Loading branch information
1 parent
8e667d3
commit 784bc31
Showing
6 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package aghnet | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/AdguardTeam/golibs/netutil" | ||
"github.com/insomniacslk/dhcp/dhcpv4/nclient4" | ||
) | ||
|
||
// listenPacketReusable announces on the local network address additionally | ||
// configuring the socket to have a reusable binding. | ||
func listenPacketReusable(ifaceName, network, address string) (c net.PacketConn, err error) { | ||
var port int | ||
_, port, err = netutil.SplitHostPort(address) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO(e.burkov): Inspect nclient4.NewRawUDPConn and implement here. | ||
return nclient4.NewRawUDPConn(ifaceName, port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:build aix || darwin || dragonfly || freebsd || netbsd || openbsd || solaris | ||
// +build aix darwin dragonfly freebsd netbsd openbsd solaris | ||
|
||
package aghnet | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"os" | ||
"syscall" | ||
|
||
"github.com/AdguardTeam/golibs/errors" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// reuseAddrCtrl is the function to be set to net.ListenConfig.Control. It | ||
// configures the socket to have a reusable port binding. | ||
func reuseAddrCtrl(_, _ string, c syscall.RawConn) (err error) { | ||
cerr := c.Control(func(fd uintptr) { | ||
// TODO(e.burkov): Consider using SO_REUSEPORT. | ||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) | ||
if err != nil { | ||
err = os.NewSyscallError("setsockopt", err) | ||
} | ||
}) | ||
|
||
const ( | ||
errMsg = "setting control options" | ||
errMsgFmt = errMsg + ": %w" | ||
) | ||
|
||
if err != nil && cerr != nil { | ||
err = errors.List(errMsg, err, cerr) | ||
} else if err != nil { | ||
err = fmt.Errorf(errMsgFmt, err) | ||
} else if cerr != nil { | ||
err = fmt.Errorf(errMsgFmt, cerr) | ||
} | ||
|
||
return err | ||
} | ||
|
||
// listenPacketReusable announces on the local network address additionally | ||
// configuring the socket to have a reusable binding. | ||
func listenPacketReusable(_, network, address string) (c net.PacketConn, err error) { | ||
var lc net.ListenConfig | ||
lc.Control = reuseAddrCtrl | ||
|
||
return lc.ListenPacket(context.Background(), network, address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package aghnet | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghos" | ||
) | ||
|
||
// listenPacketReusable announces on the local network address additionally | ||
// configuring the socket to have a reusable binding. | ||
func listenPacketReusable(_, _, _ string) (c net.PacketConn, err error) { | ||
// TODO(e.burkov): Check if we are able to control sockets on Windows | ||
// in the same way as on Unix. | ||
return nil, aghos.Unsupported("listening packet reusable") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters