summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/adapters/gonet/gonet.go
diff options
context:
space:
mode:
authorMarek Majkowski <marek@cloudflare.com>2020-01-22 12:50:28 +0000
committerMarek Majkowski <marek@cloudflare.com>2020-01-27 13:51:15 +0000
commit45398b160f4ccc3148644dde5eb5e4610e6a2d9b (patch)
tree9bb16834d3cf5abc9b7608493e8565f1698a07b7 /pkg/tcpip/adapters/gonet/gonet.go
parent6b43cf791a74a746443f70f98d859c1246f87e2a (diff)
Expose gonet.NewPacketConn, for parity with gonet.NewConn API
gonet.Conn can be created with both gonet.NewConn and gonet.Dial. gonet.PacketConn was created only by gonet.DialUDP. This prevented us from being able to use PacketConn in udp.NewForwarder() context. This simple constructor - NewPacketConn, allows user to create correct structure from that context.
Diffstat (limited to 'pkg/tcpip/adapters/gonet/gonet.go')
-rw-r--r--pkg/tcpip/adapters/gonet/gonet.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/tcpip/adapters/gonet/gonet.go b/pkg/tcpip/adapters/gonet/gonet.go
index 3bba4028b..b659cfccf 100644
--- a/pkg/tcpip/adapters/gonet/gonet.go
+++ b/pkg/tcpip/adapters/gonet/gonet.go
@@ -556,6 +556,17 @@ type PacketConn struct {
wq *waiter.Queue
}
+// NewPacketConn creates a new PacketConn.
+func NewPacketConn(s *stack.Stack, wq *waiter.Queue, ep tcpip.Endpoint) *PacketConn {
+ c := &PacketConn{
+ stack: s,
+ ep: ep,
+ wq: wq,
+ }
+ c.deadlineTimer.init()
+ return c
+}
+
// DialUDP creates a new PacketConn.
//
// If laddr is nil, a local address is automatically chosen.