-
Notifications
You must be signed in to change notification settings - Fork 258
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/dnsproxy from 2807-bind-addr to master Updates AdguardTeam/AdGuardHome#2807. Squashed commit of the following: commit 3cfff15 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Aug 3 17:47:48 2021 +0300 proxyutil: imp docs commit 54fbad0 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Aug 3 16:59:31 2021 +0300 proxyutil: fix comments commit 722a382 Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Aug 3 16:41:05 2021 +0300 proxyutil: rm oob writing on darwin
- Loading branch information
1 parent
7b49e7c
commit 1b7a9bf
Showing
5 changed files
with
149 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build darwin | ||
// +build darwin | ||
|
||
package proxyutil | ||
|
||
import ( | ||
"net" | ||
|
||
"golang.org/x/net/ipv6" | ||
) | ||
|
||
// udpMakeOOBWithSrc makes the OOB data with a specified source IP. | ||
func udpMakeOOBWithSrc(ip net.IP) []byte { | ||
if ip4 := ip.To4(); ip4 != nil { | ||
// Do not set the IPv4 source address via OOB, because it can | ||
// cause the address to become unspecified on darwin. | ||
// | ||
// See https://github.com/AdguardTeam/AdGuardHome/issues/2807. | ||
// | ||
// TODO(e.burkov): Develop a workaround to make it write OOB | ||
// only when listening on an unspecified address. | ||
return []byte{} | ||
} | ||
|
||
return (&ipv6.ControlMessage{ | ||
Src: ip, | ||
}).Marshal() | ||
} |
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 aix || dragonfly || linux || netbsd || openbsd || freebsd || solaris | ||
// +build aix dragonfly linux netbsd openbsd freebsd solaris | ||
|
||
package proxyutil | ||
|
||
import ( | ||
"net" | ||
|
||
"golang.org/x/net/ipv4" | ||
"golang.org/x/net/ipv6" | ||
) | ||
|
||
// udpMakeOOBWithSrc makes the OOB data with a specified source IP. | ||
func udpMakeOOBWithSrc(ip net.IP) []byte { | ||
if ip4 := ip.To4(); ip4 != nil { | ||
return (&ipv4.ControlMessage{ | ||
Src: ip, | ||
}).Marshal() | ||
} | ||
|
||
return (&ipv6.ControlMessage{ | ||
Src: ip, | ||
}).Marshal() | ||
} |
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,36 @@ | ||
package proxyutil | ||
|
||
import "net" | ||
|
||
// UDPGetOOBSize returns maximum size of the received OOB data. | ||
func UDPGetOOBSize() (oobSize int) { | ||
return udpGetOOBSize() | ||
} | ||
|
||
// UDPSetOptions sets flag options on a UDP socket to be able to receive the | ||
// necessary OOB data. | ||
func UDPSetOptions(c *net.UDPConn) (err error) { | ||
return udpSetOptions(c) | ||
} | ||
|
||
// UDPRead udpRead reads the message from c using buf receives payload of size | ||
// udpOOBSize from the UDP socket. It returns the number of bytes copied into | ||
// buf, the number of bytes copied with OOB and the source address of the | ||
// message. | ||
func UDPRead( | ||
c *net.UDPConn, | ||
buf []byte, | ||
udpOOBSize int, | ||
) (n int, localIP net.IP, remoteAddr *net.UDPAddr, err error) { | ||
return udpRead(c, buf, udpOOBSize) | ||
} | ||
|
||
// UDPWrite writes the data to the remoteAddr using conn. | ||
func UDPWrite( | ||
data []byte, | ||
conn *net.UDPConn, | ||
remoteAddr *net.UDPAddr, | ||
localIP net.IP, | ||
) (n int, err error) { | ||
return udpWrite(data, conn, remoteAddr, localIP) | ||
} |
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 |
---|---|---|
@@ -1,30 +1,28 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package proxyutil | ||
|
||
import "net" | ||
|
||
// UDPGetOOBSize - get max. size of received OOB data | ||
// Does nothing on Windows | ||
func UDPGetOOBSize() int { | ||
func udpGetOOBSize() int { | ||
return 0 | ||
} | ||
|
||
// UDPSetOptions - set options on a UDP socket to be able to receive the necessary OOB data | ||
// Does nothing on Windows | ||
func UDPSetOptions(c *net.UDPConn) error { | ||
func udpSetOptions(c *net.UDPConn) error { | ||
return nil | ||
} | ||
|
||
// UDPRead - receive payload from the UDP socket | ||
func UDPRead(c *net.UDPConn, buf []byte, _ int) (int, net.IP, *net.UDPAddr, error) { | ||
func udpRead(c *net.UDPConn, buf []byte, _ int) (int, net.IP, *net.UDPAddr, error) { | ||
n, addr, err := c.ReadFrom(buf) | ||
var udpAddr *net.UDPAddr | ||
if addr != nil { | ||
udpAddr = addr.(*net.UDPAddr) | ||
} | ||
|
||
return n, nil, udpAddr, err | ||
} | ||
|
||
// UDPWrite - writes to the UDP socket | ||
func UDPWrite(bytes []byte, conn *net.UDPConn, remoteAddr *net.UDPAddr, _ net.IP) (int, error) { | ||
func udpWrite(bytes []byte, conn *net.UDPConn, remoteAddr *net.UDPAddr, _ net.IP) (int, error) { | ||
return conn.WriteTo(bytes, remoteAddr) | ||
} |