mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-11 17:31:12 +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
33 lines
526 B
Go
33 lines
526 B
Go
package wgproxy
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
const (
|
|
portRangeStart = 3128
|
|
portRangeEnd = 3228
|
|
)
|
|
|
|
type portLookup struct {
|
|
}
|
|
|
|
func (pl portLookup) searchFreePort() (int, error) {
|
|
for i := portRangeStart; i <= portRangeEnd; i++ {
|
|
if pl.tryToBind(i) == nil {
|
|
return i, nil
|
|
}
|
|
}
|
|
return 0, fmt.Errorf("failed to bind free port for eBPF proxy")
|
|
}
|
|
|
|
func (pl portLookup) tryToBind(port int) error {
|
|
l, err := net.ListenPacket("udp", fmt.Sprintf(":%d", port))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_ = l.Close()
|
|
return nil
|
|
}
|