summaryrefslogtreecommitdiffhomepage
path: root/test/iptables/iptables_util.go
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-01-21 13:16:25 -0800
committerKevin Krakauer <krakauer@google.com>2020-01-21 13:16:25 -0800
commit62357a0afb5f4128a11dc9a1dfadd2957ec39e2d (patch)
tree2f93dc1bb5680434f3bcd69df60d45af89777a94 /test/iptables/iptables_util.go
parentbd292894097ffdf316bc78d81aebd0a2988124f3 (diff)
parent2ba6198851dc1e293295d7cadf8c0ae456b68beb (diff)
Merge branch 'master' into iptables-write-filter-proto
Diffstat (limited to 'test/iptables/iptables_util.go')
-rw-r--r--test/iptables/iptables_util.go32
1 files changed, 21 insertions, 11 deletions
diff --git a/test/iptables/iptables_util.go b/test/iptables/iptables_util.go
index 3dcaafb79..b40d0dc4f 100644
--- a/test/iptables/iptables_util.go
+++ b/test/iptables/iptables_util.go
@@ -83,32 +83,42 @@ func sendUDPLoop(ip net.IP, port int, duration time.Duration) error {
return nil
}
+// listenTCP listens for connections on a TCP port.
func listenTCP(port int, timeout time.Duration) error {
- localAddr := net.TCPAddr{Port: acceptPort}
- listener, err := net.ListenTCP("tcp4", &localAddr)
+ localAddr := net.TCPAddr{
+ Port: port,
+ }
+
+ // Starts listening on port.
+ lConn, err := net.ListenTCP("tcp4", &localAddr)
if err != nil {
return err
}
- defer listener.Close()
- listener.SetDeadline(time.Now().Add(timeout))
- conn, err := listener.AcceptTCP()
+ defer lConn.Close()
+
+ // Accept connections on port.
+ lConn.SetDeadline(time.Now().Add(timeout))
+ conn, err := lConn.AcceptTCP()
if err != nil {
- return fmt.Errorf("failed to establish a connection %v", err)
+ return err
}
- defer conn.Close()
-
+ conn.Close()
return nil
}
-func connectLoopTCP(ip net.IP, port int, timeout time.Duration) error {
+// connectTCP connects the TCP server over specified local port, server IP and remote/server port.
+func connectTCP(ip net.IP, remotePort, localPort int, timeout time.Duration) error {
contAddr := net.TCPAddr{
IP: ip,
- Port: port,
+ Port: remotePort,
}
// The container may not be listening when we first connect, so retry
// upon error.
cb := func() error {
- conn, err := net.DialTCP("tcp4", nil, &contAddr)
+ localAddr := net.TCPAddr{
+ Port: localPort,
+ }
+ conn, err := net.DialTCP("tcp4", &localAddr, &contAddr)
if conn != nil {
conn.Close()
}