mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-02 13:03:56 +01:00
b0364da67c
EBPF proxy between TURN (relay) and WireGuard to reduce number of used ports used by the NetBird agent. - Separate the wg configuration from the proxy logic - In case if eBPF type proxy has only one single proxy instance - In case if the eBPF is not supported fallback to the original proxy Implementation Between the signature of eBPF type proxy and original proxy has differences so this is why the factory structure exists
43 lines
737 B
Go
43 lines
737 B
Go
package wgproxy
|
|
|
|
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
|
|
}
|