summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2021-02-19 23:41:16 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2021-11-03 22:18:02 +0100
commitc277724e67bffa65112c506e23dd864c6de5b925 (patch)
tree6d7467b3511b9555135e04c240741c9724421691
parent52704c4b928889f88b1c8effcd02788000e2a780 (diff)
netstack: allow listening to 0.0.0.0 and ::fix/listen-any-addresses
convertToFullAddr: Replace 0.0.0.0 and :: with the empty string, which is used by Gvisor's tcpip stack to represent the unspecified addresses. This fixes the following errors when using an unspecified address in a call to ListenTCP: tnet.ListenTCP(&net.TCPAddr{IP: net.ParseIP("::"), Port: 80}) > panic: bind tcp 0.0.0.0:80: bad local address tnet.ListenTCP(&net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: 80}) > panic: bind tcp [::]:80: bad local address Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
-rw-r--r--tun/netstack/tun.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go
index 24d0835..6212493 100644
--- a/tun/netstack/tun.go
+++ b/tun/netstack/tun.go
@@ -204,15 +204,23 @@ func (tun *netTun) MTU() (int, error) {
func convertToFullAddr(ip net.IP, port int) (tcpip.FullAddress, tcpip.NetworkProtocolNumber) {
if ip4 := ip.To4(); ip4 != nil {
+ addr := tcpip.Address(ip4)
+ if addr == header.IPv4Any {
+ addr = ""
+ }
return tcpip.FullAddress{
NIC: 1,
- Addr: tcpip.Address(ip4),
+ Addr: addr,
Port: uint16(port),
}, ipv4.ProtocolNumber
} else {
+ addr := tcpip.Address(ip)
+ if addr == header.IPv6Any {
+ addr = ""
+ }
return tcpip.FullAddress{
NIC: 1,
- Addr: tcpip.Address(ip),
+ Addr: addr,
Port: uint16(port),
}, ipv6.ProtocolNumber
}