mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-27 10:33:11 +01:00
2475473227
All routes are now installed in a custom netbird routing table. Management and wireguard traffic is now marked with a custom fwmark. When the mark is present the traffic is routed via the main routing table, bypassing the VPN. When the mark is absent the traffic is routed via the netbird routing table, if: - there's no match in the main routing table - it would match the default route in the routing table IPv6 traffic is blocked when a default route IPv4 route is configured to avoid leakage.
35 lines
616 B
Go
35 lines
616 B
Go
package wgproxy
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
nbnet "github.com/netbirdio/netbird/util/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 := nbnet.NewListener().ListenPacket(context.Background(), "udp", fmt.Sprintf(":%d", port))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_ = l.Close()
|
|
return nil
|
|
}
|