2023-07-26 16:21:04 +02:00
|
|
|
//go:build !android
|
|
|
|
|
2023-07-26 14:00:47 +02:00
|
|
|
package wgproxy
|
|
|
|
|
|
|
|
import (
|
2024-05-07 18:50:34 +02:00
|
|
|
"context"
|
|
|
|
|
2023-07-26 14:00:47 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2024-06-22 15:33:10 +02:00
|
|
|
func NewFactory(ctx context.Context, userspace bool, wgPort int) *Factory {
|
2023-07-26 14:00:47 +02:00
|
|
|
f := &Factory{wgPort: wgPort}
|
|
|
|
|
2024-06-22 15:33:10 +02:00
|
|
|
if userspace {
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2024-05-07 18:50:34 +02:00
|
|
|
ebpfProxy := NewWGEBPFProxy(ctx, wgPort)
|
|
|
|
err := ebpfProxy.listen()
|
2023-07-26 14:00:47 +02:00
|
|
|
if err != nil {
|
2023-08-03 18:24:23 +02:00
|
|
|
log.Warnf("failed to initialize ebpf proxy, fallback to user space proxy: %s", err)
|
2023-07-26 14:00:47 +02:00
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
f.ebpfProxy = ebpfProxy
|
|
|
|
return f
|
|
|
|
}
|