mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 19:00:50 +01:00
4ebf6e1c4c
Port the conn close call to eBPF proxy
51 lines
902 B
Go
51 lines
902 B
Go
//go:build !android
|
|
|
|
package wgproxy
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/wgproxy/ebpf"
|
|
"github.com/netbirdio/netbird/client/internal/wgproxy/usp"
|
|
)
|
|
|
|
type Factory struct {
|
|
wgPort int
|
|
ebpfProxy *ebpf.WGEBPFProxy
|
|
}
|
|
|
|
func NewFactory(userspace bool, wgPort int) *Factory {
|
|
f := &Factory{wgPort: wgPort}
|
|
|
|
if userspace {
|
|
return f
|
|
}
|
|
|
|
ebpfProxy := ebpf.NewWGEBPFProxy(wgPort)
|
|
err := ebpfProxy.Listen()
|
|
if err != nil {
|
|
log.Warnf("failed to initialize ebpf proxy, fallback to user space proxy: %s", err)
|
|
return f
|
|
}
|
|
|
|
f.ebpfProxy = ebpfProxy
|
|
return f
|
|
}
|
|
|
|
func (w *Factory) GetProxy() Proxy {
|
|
if w.ebpfProxy != nil {
|
|
p := &ebpf.ProxyWrapper{
|
|
WgeBPFProxy: w.ebpfProxy,
|
|
}
|
|
return p
|
|
}
|
|
return usp.NewWGUserSpaceProxy(w.wgPort)
|
|
}
|
|
|
|
func (w *Factory) Free() error {
|
|
if w.ebpfProxy == nil {
|
|
return nil
|
|
}
|
|
return w.ebpfProxy.Free()
|
|
}
|