aboutsummaryrefslogtreecommitdiff
path: root/conn/conn.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-03-31 13:55:18 -0700
committerJason A. Donenfeld <Jason@zx2c4.com>2021-04-02 11:07:08 -0600
commit10533c3e73cdb6f4c4f19e01464782b69ace739e (patch)
treec19f5ce9c6785b22e72afec19d2a73a0d818e0c6 /conn/conn.go
parent8ed83e0427a693db6d909897dc73bf7ce6e22b21 (diff)
downloadwireguard-go-10533c3e73cdb6f4c4f19e01464782b69ace739e.tar.gz
wireguard-go-10533c3e73cdb6f4c4f19e01464782b69ace739e.zip
all: make conn.Bind.Open return a slice of receive functions
Instead of hard-coding exactly two sources from which to receive packets (an IPv4 source and an IPv6 source), allow the conn.Bind to specify a set of sources. Beneficial consequences: * If there's no IPv6 support on a system, conn.Bind.Open can choose not to return a receive function for it, which is simpler than tracking that state in the bind. This simplification removes existing data races from both conn.StdNetBind and bindtest.ChannelBind. * If there are more than two sources on a system, the conn.Bind no longer needs to add a separate muxing layer. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'conn/conn.go')
-rw-r--r--conn/conn.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/conn/conn.go b/conn/conn.go
index 6fd232f..3c7fcd0 100644
--- a/conn/conn.go
+++ b/conn/conn.go
@@ -12,6 +12,11 @@ import (
"strings"
)
+// A ReceiveFunc receives a single inbound packet from the network.
+// It writes the data into b. n is the length of the packet.
+// ep is the remote endpoint.
+type ReceiveFunc func(b []byte) (n int, ep Endpoint, err error)
+
// A Bind listens on a port for both IPv6 and IPv4 UDP traffic.
//
// A Bind interface may also be a PeekLookAtSocketFd or BindSocketToInterface,
@@ -19,23 +24,17 @@ import (
type Bind interface {
// Open puts the Bind into a listening state on a given port and reports the actual
// port that it bound to. Passing zero results in a random selection.
- Open(port uint16) (actualPort uint16, err error)
+ // fns is the set of functions that will be called to receive packets.
+ Open(port uint16) (fns []ReceiveFunc, actualPort uint16, err error)
// Close closes the Bind listener.
+ // All fns returned by Open must return net.ErrClosed after a call to Close.
Close() error
// SetMark sets the mark for each packet sent through this Bind.
// This mark is passed to the kernel as the socket option SO_MARK.
SetMark(mark uint32) error
- // ReceiveIPv6 reads an IPv6 UDP packet into b. It reports the number of bytes read,
- // n, the packet source address ep, and any error.
- ReceiveIPv6(b []byte) (n int, ep Endpoint, err error)
-
- // ReceiveIPv4 reads an IPv4 UDP packet into b. It reports the number of bytes read,
- // n, the packet source address ep, and any error.
- ReceiveIPv4(b []byte) (n int, ep Endpoint, err error)
-
// Send writes a packet b to address ep.
Send(b []byte, ep Endpoint) error