mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-12 09:50:47 +01:00
30ebcf38c7
In the case of user space WireGuard mode, use in-memory proxy between the TURN/Relay connection and the WireGuard Bind. We keep the UDP proxy and eBPF proxy for kernel mode. The key change is the new wgproxy/bind and the iface/bind/ice_bind changes. Everything else is just to fulfill the dependencies.
43 lines
734 B
Go
43 lines
734 B
Go
package ebpf
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func Test_portLookup_searchFreePort(t *testing.T) {
|
|
pl := portLookup{}
|
|
_, err := pl.searchFreePort()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func Test_portLookup_on_allocated(t *testing.T) {
|
|
pl := portLookup{}
|
|
|
|
allocatedPort, err := allocatePort(portRangeStart)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer allocatedPort.Close()
|
|
|
|
fp, err := pl.searchFreePort()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if fp != (portRangeStart + 1) {
|
|
t.Errorf("invalid free port, expected: %d, got: %d", portRangeStart+1, fp)
|
|
}
|
|
}
|
|
|
|
func allocatePort(port int) (net.PacketConn, error) {
|
|
c, err := net.ListenPacket("udp", fmt.Sprintf(":%d", port))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c, err
|
|
}
|