mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-19 11:20:18 +02:00
Use uint16
This commit is contained in:
@@ -74,7 +74,7 @@ var (
|
|||||||
anonymizeFlag bool
|
anonymizeFlag bool
|
||||||
dnsRouteInterval time.Duration
|
dnsRouteInterval time.Duration
|
||||||
lazyConnEnabled bool
|
lazyConnEnabled bool
|
||||||
mtu int
|
mtu uint16
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "netbird",
|
Use: "netbird",
|
||||||
|
@@ -54,7 +54,7 @@ func init() {
|
|||||||
upCmd.PersistentFlags().BoolVarP(&foregroundMode, "foreground-mode", "F", false, "start service in foreground")
|
upCmd.PersistentFlags().BoolVarP(&foregroundMode, "foreground-mode", "F", false, "start service in foreground")
|
||||||
upCmd.PersistentFlags().StringVar(&interfaceName, interfaceNameFlag, iface.WgInterfaceDefault, "Wireguard interface name")
|
upCmd.PersistentFlags().StringVar(&interfaceName, interfaceNameFlag, iface.WgInterfaceDefault, "Wireguard interface name")
|
||||||
upCmd.PersistentFlags().Uint16Var(&wireguardPort, wireguardPortFlag, iface.DefaultWgPort, "Wireguard interface listening port")
|
upCmd.PersistentFlags().Uint16Var(&wireguardPort, wireguardPortFlag, iface.DefaultWgPort, "Wireguard interface listening port")
|
||||||
upCmd.PersistentFlags().IntVar(&mtu, mtuFlag, iface.DefaultMTU, "Set MTU (Maximum Transmission Unit) for the WireGuard interface")
|
upCmd.PersistentFlags().Uint16Var(&mtu, mtuFlag, iface.DefaultMTU, "Set MTU (Maximum Transmission Unit) for the WireGuard interface")
|
||||||
upCmd.PersistentFlags().BoolVarP(&networkMonitor, networkMonitorFlag, "N", networkMonitor,
|
upCmd.PersistentFlags().BoolVarP(&networkMonitor, networkMonitorFlag, "N", networkMonitor,
|
||||||
`Manage network monitoring. Defaults to true on Windows and macOS, false on Linux and FreeBSD. `+
|
`Manage network monitoring. Defaults to true on Windows and macOS, false on Linux and FreeBSD. `+
|
||||||
`E.g. --network-monitor=false to disable or --network-monitor=true to enable.`,
|
`E.g. --network-monitor=false to disable or --network-monitor=true to enable.`,
|
||||||
@@ -419,7 +419,7 @@ func setupLoginRequest(providedSetupKey string, customDNSAddressConverted []byte
|
|||||||
return &loginRequest, nil
|
return &loginRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateMTU(mtu int) error {
|
func validateMTU(mtu uint16) error {
|
||||||
if mtu < iface.MinMTU {
|
if mtu < iface.MinMTU {
|
||||||
return fmt.Errorf("MTU %d below minimum (%d bytes)", mtu, iface.MinMTU)
|
return fmt.Errorf("MTU %d below minimum (%d bytes)", mtu, iface.MinMTU)
|
||||||
}
|
}
|
||||||
|
@@ -56,11 +56,11 @@ type ICEBind struct {
|
|||||||
muUDPMux sync.Mutex
|
muUDPMux sync.Mutex
|
||||||
udpMux *UniversalUDPMuxDefault
|
udpMux *UniversalUDPMuxDefault
|
||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
mtu int
|
mtu uint16
|
||||||
activityRecorder *ActivityRecorder
|
activityRecorder *ActivityRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewICEBind(transportNet transport.Net, filterFn FilterFn, address wgaddr.Address, mtu int) *ICEBind {
|
func NewICEBind(transportNet transport.Net, filterFn FilterFn, address wgaddr.Address, mtu uint16) *ICEBind {
|
||||||
b, _ := wgConn.NewStdNetBind().(*wgConn.StdNetBind)
|
b, _ := wgConn.NewStdNetBind().(*wgConn.StdNetBind)
|
||||||
ib := &ICEBind{
|
ib := &ICEBind{
|
||||||
StdNetBind: b,
|
StdNetBind: b,
|
||||||
@@ -82,7 +82,7 @@ func NewICEBind(transportNet transport.Net, filterFn FilterFn, address wgaddr.Ad
|
|||||||
return ib
|
return ib
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ICEBind) MTU() int {
|
func (s *ICEBind) MTU() uint16 {
|
||||||
return s.mtu
|
return s.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,11 +18,10 @@ import (
|
|||||||
"github.com/pion/stun/v2"
|
"github.com/pion/stun/v2"
|
||||||
"github.com/pion/transport/v3"
|
"github.com/pion/transport/v3"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/iface/wgaddr"
|
|
||||||
"github.com/netbirdio/netbird/client/iface/bufsize"
|
"github.com/netbirdio/netbird/client/iface/bufsize"
|
||||||
|
"github.com/netbirdio/netbird/client/iface/wgaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// FilterFn is a function that filters out candidates based on the address.
|
// FilterFn is a function that filters out candidates based on the address.
|
||||||
// If it returns true, the address is to be filtered. It also returns the prefix of matching route.
|
// If it returns true, the address is to be filtered. It also returns the prefix of matching route.
|
||||||
type FilterFn func(address netip.Addr) (bool, netip.Prefix, error)
|
type FilterFn func(address netip.Addr) (bool, netip.Prefix, error)
|
||||||
@@ -46,7 +45,7 @@ type UniversalUDPMuxParams struct {
|
|||||||
Net transport.Net
|
Net transport.Net
|
||||||
FilterFn FilterFn
|
FilterFn FilterFn
|
||||||
WGAddress wgaddr.Address
|
WGAddress wgaddr.Address
|
||||||
MTU int
|
MTU uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUniversalUDPMuxDefault creates an implementation of UniversalUDPMux embedding UDPMux
|
// NewUniversalUDPMuxDefault creates an implementation of UniversalUDPMux embedding UDPMux
|
||||||
|
9
client/iface/bufsize/bufsize.go
Normal file
9
client/iface/bufsize/bufsize.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package bufsize
|
||||||
|
|
||||||
|
const (
|
||||||
|
// WGBufferOverhead represents the additional buffer space needed beyond MTU
|
||||||
|
// for WireGuard packet encapsulation (WG header + UDP + IP + safety margin)
|
||||||
|
// Original hardcoded buffers were 1500, default MTU is 1280, so overhead = 220
|
||||||
|
// TODO: Calculate this properly based on actual protocol overhead instead of using hardcoded difference
|
||||||
|
WGBufferOverhead = 220
|
||||||
|
)
|
@@ -17,7 +17,7 @@ type WGTunDevice interface {
|
|||||||
Up() (*bind.UniversalUDPMuxDefault, error)
|
Up() (*bind.UniversalUDPMuxDefault, error)
|
||||||
UpdateAddr(address wgaddr.Address) error
|
UpdateAddr(address wgaddr.Address) error
|
||||||
WgAddress() wgaddr.Address
|
WgAddress() wgaddr.Address
|
||||||
MTU() int
|
MTU() uint16
|
||||||
DeviceName() string
|
DeviceName() string
|
||||||
Close() error
|
Close() error
|
||||||
FilteredDevice() *device.FilteredDevice
|
FilteredDevice() *device.FilteredDevice
|
||||||
|
@@ -21,7 +21,7 @@ type WGTunDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
port int
|
port int
|
||||||
key string
|
key string
|
||||||
mtu int
|
mtu uint16
|
||||||
iceBind *bind.ICEBind
|
iceBind *bind.ICEBind
|
||||||
tunAdapter TunAdapter
|
tunAdapter TunAdapter
|
||||||
disableDNS bool
|
disableDNS bool
|
||||||
@@ -33,7 +33,7 @@ type WGTunDevice struct {
|
|||||||
configurer WGConfigurer
|
configurer WGConfigurer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTunDevice(address wgaddr.Address, port int, key string, mtu int, iceBind *bind.ICEBind, tunAdapter TunAdapter, disableDNS bool) *WGTunDevice {
|
func NewTunDevice(address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind, tunAdapter TunAdapter, disableDNS bool) *WGTunDevice {
|
||||||
return &WGTunDevice{
|
return &WGTunDevice{
|
||||||
address: address,
|
address: address,
|
||||||
port: port,
|
port: port,
|
||||||
@@ -58,7 +58,7 @@ func (t *WGTunDevice) Create(routes []string, dns string, searchDomains []string
|
|||||||
searchDomainsToString = ""
|
searchDomainsToString = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fd, err := t.tunAdapter.ConfigureInterface(t.address.String(), t.mtu, dns, searchDomainsToString, routesString)
|
fd, err := t.tunAdapter.ConfigureInterface(t.address.String(), int(t.mtu), dns, searchDomainsToString, routesString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to create Android interface: %s", err)
|
log.Errorf("failed to create Android interface: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -137,7 +137,7 @@ func (t *WGTunDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *WGTunDevice) MTU() int {
|
func (t *WGTunDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ type TunDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
port int
|
port int
|
||||||
key string
|
key string
|
||||||
mtu int
|
mtu uint16
|
||||||
iceBind *bind.ICEBind
|
iceBind *bind.ICEBind
|
||||||
|
|
||||||
device *device.Device
|
device *device.Device
|
||||||
@@ -30,7 +30,7 @@ type TunDevice struct {
|
|||||||
configurer WGConfigurer
|
configurer WGConfigurer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu int, iceBind *bind.ICEBind) *TunDevice {
|
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind) *TunDevice {
|
||||||
return &TunDevice{
|
return &TunDevice{
|
||||||
name: name,
|
name: name,
|
||||||
address: address,
|
address: address,
|
||||||
@@ -42,7 +42,7 @@ func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TunDevice) Create() (WGConfigurer, error) {
|
func (t *TunDevice) Create() (WGConfigurer, error) {
|
||||||
tunDevice, err := tun.CreateTUN(t.name, t.mtu)
|
tunDevice, err := tun.CreateTUN(t.name, int(t.mtu))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating tun device: %s", err)
|
return nil, fmt.Errorf("error creating tun device: %s", err)
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ func (t *TunDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TunDevice) MTU() int {
|
func (t *TunDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@ type TunDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
port int
|
port int
|
||||||
key string
|
key string
|
||||||
|
mtu uint16
|
||||||
iceBind *bind.ICEBind
|
iceBind *bind.ICEBind
|
||||||
tunFd int
|
tunFd int
|
||||||
|
|
||||||
@@ -31,12 +32,13 @@ type TunDevice struct {
|
|||||||
configurer WGConfigurer
|
configurer WGConfigurer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTunDevice(name string, address wgaddr.Address, port int, key string, iceBind *bind.ICEBind, tunFd int) *TunDevice {
|
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind, tunFd int) *TunDevice {
|
||||||
return &TunDevice{
|
return &TunDevice{
|
||||||
name: name,
|
name: name,
|
||||||
address: address,
|
address: address,
|
||||||
port: port,
|
port: port,
|
||||||
key: key,
|
key: key,
|
||||||
|
mtu: mtu,
|
||||||
iceBind: iceBind,
|
iceBind: iceBind,
|
||||||
tunFd: tunFd,
|
tunFd: tunFd,
|
||||||
}
|
}
|
||||||
@@ -125,7 +127,7 @@ func (t *TunDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TunDevice) MTU() int {
|
func (t *TunDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ type TunKernelDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
wgPort int
|
wgPort int
|
||||||
key string
|
key string
|
||||||
mtu int
|
mtu uint16
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
ctxCancel context.CancelFunc
|
ctxCancel context.CancelFunc
|
||||||
transportNet transport.Net
|
transportNet transport.Net
|
||||||
@@ -35,7 +35,7 @@ type TunKernelDevice struct {
|
|||||||
filterFn bind.FilterFn
|
filterFn bind.FilterFn
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKernelDevice(name string, address wgaddr.Address, wgPort int, key string, mtu int, transportNet transport.Net) *TunKernelDevice {
|
func NewKernelDevice(name string, address wgaddr.Address, wgPort int, key string, mtu uint16, transportNet transport.Net) *TunKernelDevice {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
return &TunKernelDevice{
|
return &TunKernelDevice{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
@@ -65,7 +65,7 @@ func (t *TunKernelDevice) Create() (WGConfigurer, error) {
|
|||||||
// TODO: do a MTU discovery
|
// TODO: do a MTU discovery
|
||||||
log.Debugf("setting MTU: %d interface: %s", t.mtu, t.name)
|
log.Debugf("setting MTU: %d interface: %s", t.mtu, t.name)
|
||||||
|
|
||||||
if err := link.setMTU(t.mtu); err != nil {
|
if err := link.setMTU(int(t.mtu)); err != nil {
|
||||||
return nil, fmt.Errorf("set mtu: %w", err)
|
return nil, fmt.Errorf("set mtu: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ func (t *TunKernelDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TunKernelDevice) MTU() int {
|
func (t *TunKernelDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ type TunNetstackDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
port int
|
port int
|
||||||
key string
|
key string
|
||||||
mtu int
|
mtu uint16
|
||||||
listenAddress string
|
listenAddress string
|
||||||
iceBind *bind.ICEBind
|
iceBind *bind.ICEBind
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ type TunNetstackDevice struct {
|
|||||||
net *netstack.Net
|
net *netstack.Net
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNetstackDevice(name string, address wgaddr.Address, wgPort int, key string, mtu int, iceBind *bind.ICEBind, listenAddress string) *TunNetstackDevice {
|
func NewNetstackDevice(name string, address wgaddr.Address, wgPort int, key string, mtu uint16, iceBind *bind.ICEBind, listenAddress string) *TunNetstackDevice {
|
||||||
return &TunNetstackDevice{
|
return &TunNetstackDevice{
|
||||||
name: name,
|
name: name,
|
||||||
address: address,
|
address: address,
|
||||||
@@ -57,7 +57,7 @@ func (t *TunNetstackDevice) Create() (WGConfigurer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("netstack using address: %s", t.address.IP)
|
log.Debugf("netstack using address: %s", t.address.IP)
|
||||||
t.nsTun = nbnetstack.NewNetStackTun(t.listenAddress, t.address.IP, dnsAddr, t.mtu)
|
t.nsTun = nbnetstack.NewNetStackTun(t.listenAddress, t.address.IP, dnsAddr, int(t.mtu))
|
||||||
log.Debugf("netstack using dns address: %s", dnsAddr)
|
log.Debugf("netstack using dns address: %s", dnsAddr)
|
||||||
tunIface, net, err := t.nsTun.Create()
|
tunIface, net, err := t.nsTun.Create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,7 +125,7 @@ func (t *TunNetstackDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TunNetstackDevice) MTU() int {
|
func (t *TunNetstackDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ type USPDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
port int
|
port int
|
||||||
key string
|
key string
|
||||||
mtu int
|
mtu uint16
|
||||||
iceBind *bind.ICEBind
|
iceBind *bind.ICEBind
|
||||||
|
|
||||||
device *device.Device
|
device *device.Device
|
||||||
@@ -29,7 +29,7 @@ type USPDevice struct {
|
|||||||
configurer WGConfigurer
|
configurer WGConfigurer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUSPDevice(name string, address wgaddr.Address, port int, key string, mtu int, iceBind *bind.ICEBind) *USPDevice {
|
func NewUSPDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind) *USPDevice {
|
||||||
log.Infof("using userspace bind mode")
|
log.Infof("using userspace bind mode")
|
||||||
|
|
||||||
return &USPDevice{
|
return &USPDevice{
|
||||||
@@ -44,9 +44,9 @@ func NewUSPDevice(name string, address wgaddr.Address, port int, key string, mtu
|
|||||||
|
|
||||||
func (t *USPDevice) Create() (WGConfigurer, error) {
|
func (t *USPDevice) Create() (WGConfigurer, error) {
|
||||||
log.Info("create tun interface")
|
log.Info("create tun interface")
|
||||||
tunIface, err := tun.CreateTUN(t.name, t.mtu)
|
tunIface, err := tun.CreateTUN(t.name, int(t.mtu))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("failed to create tun interface (%s, %d): %s", t.name, t.mtu, err)
|
log.Debugf("failed to create tun interface (%s, %d): %s", t.name, int(t.mtu), err)
|
||||||
return nil, fmt.Errorf("error creating tun device: %s", err)
|
return nil, fmt.Errorf("error creating tun device: %s", err)
|
||||||
}
|
}
|
||||||
t.filteredDevice = newDeviceFilter(tunIface)
|
t.filteredDevice = newDeviceFilter(tunIface)
|
||||||
@@ -118,7 +118,7 @@ func (t *USPDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *USPDevice) MTU() int {
|
func (t *USPDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ type TunDevice struct {
|
|||||||
address wgaddr.Address
|
address wgaddr.Address
|
||||||
port int
|
port int
|
||||||
key string
|
key string
|
||||||
mtu int
|
mtu uint16
|
||||||
iceBind *bind.ICEBind
|
iceBind *bind.ICEBind
|
||||||
|
|
||||||
device *device.Device
|
device *device.Device
|
||||||
@@ -33,7 +33,7 @@ type TunDevice struct {
|
|||||||
configurer WGConfigurer
|
configurer WGConfigurer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu int, iceBind *bind.ICEBind) *TunDevice {
|
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind) *TunDevice {
|
||||||
return &TunDevice{
|
return &TunDevice{
|
||||||
name: name,
|
name: name,
|
||||||
address: address,
|
address: address,
|
||||||
@@ -59,7 +59,7 @@ func (t *TunDevice) Create() (WGConfigurer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Info("create tun interface")
|
log.Info("create tun interface")
|
||||||
tunDevice, err := tun.CreateTUNWithRequestedGUID(t.name, &guid, t.mtu)
|
tunDevice, err := tun.CreateTUNWithRequestedGUID(t.name, &guid, int(t.mtu))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating tun device: %s", err)
|
return nil, fmt.Errorf("error creating tun device: %s", err)
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ func (t *TunDevice) WgAddress() wgaddr.Address {
|
|||||||
return t.address
|
return t.address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TunDevice) MTU() int {
|
func (t *TunDevice) MTU() uint16 {
|
||||||
return t.mtu
|
return t.mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@ type WGTunDevice interface {
|
|||||||
Up() (*bind.UniversalUDPMuxDefault, error)
|
Up() (*bind.UniversalUDPMuxDefault, error)
|
||||||
UpdateAddr(address wgaddr.Address) error
|
UpdateAddr(address wgaddr.Address) error
|
||||||
WgAddress() wgaddr.Address
|
WgAddress() wgaddr.Address
|
||||||
MTU() int
|
MTU() uint16
|
||||||
DeviceName() string
|
DeviceName() string
|
||||||
Close() error
|
Close() error
|
||||||
FilteredDevice() *device.FilteredDevice
|
FilteredDevice() *device.FilteredDevice
|
||||||
|
@@ -47,7 +47,7 @@ type WGIFaceOpts struct {
|
|||||||
Address string
|
Address string
|
||||||
WGPort int
|
WGPort int
|
||||||
WGPrivKey string
|
WGPrivKey string
|
||||||
MTU int
|
MTU uint16
|
||||||
MobileArgs *device.MobileIFaceArguments
|
MobileArgs *device.MobileIFaceArguments
|
||||||
TransportNet transport.Net
|
TransportNet transport.Net
|
||||||
FilterFn bind.FilterFn
|
FilterFn bind.FilterFn
|
||||||
@@ -84,7 +84,7 @@ func (w *WGIface) Address() wgaddr.Address {
|
|||||||
return w.tun.WgAddress()
|
return w.tun.WgAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WGIface) MTU() int {
|
func (w *WGIface) MTU() uint16 {
|
||||||
return w.tun.MTU()
|
return w.tun.MTU()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ func NewWGIFace(opts WGIFaceOpts) (*WGIface, error) {
|
|||||||
iceBind := bind.NewICEBind(opts.TransportNet, opts.FilterFn, wgAddress, opts.MTU)
|
iceBind := bind.NewICEBind(opts.TransportNet, opts.FilterFn, wgAddress, opts.MTU)
|
||||||
|
|
||||||
wgIFace := &WGIface{
|
wgIFace := &WGIface{
|
||||||
tun: device.NewTunDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, iceBind, opts.MobileArgs.TunFd),
|
tun: device.NewTunDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, opts.MTU, iceBind, opts.MobileArgs.TunFd),
|
||||||
userspaceBind: true,
|
userspaceBind: true,
|
||||||
wgProxyFactory: wgproxy.NewUSPFactory(iceBind),
|
wgProxyFactory: wgproxy.NewUSPFactory(iceBind),
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,8 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/iface/bind"
|
"github.com/netbirdio/netbird/client/iface/bind"
|
||||||
"github.com/netbirdio/netbird/client/iface/wgproxy/listener"
|
|
||||||
"github.com/netbirdio/netbird/client/iface/bufsize"
|
"github.com/netbirdio/netbird/client/iface/bufsize"
|
||||||
|
"github.com/netbirdio/netbird/client/iface/wgproxy/listener"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProxyBind struct {
|
type ProxyBind struct {
|
||||||
|
@@ -17,10 +17,10 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
nberrors "github.com/netbirdio/netbird/client/errors"
|
nberrors "github.com/netbirdio/netbird/client/errors"
|
||||||
|
"github.com/netbirdio/netbird/client/iface/bufsize"
|
||||||
"github.com/netbirdio/netbird/client/internal/ebpf"
|
"github.com/netbirdio/netbird/client/internal/ebpf"
|
||||||
ebpfMgr "github.com/netbirdio/netbird/client/internal/ebpf/manager"
|
ebpfMgr "github.com/netbirdio/netbird/client/internal/ebpf/manager"
|
||||||
nbnet "github.com/netbirdio/netbird/util/net"
|
nbnet "github.com/netbirdio/netbird/util/net"
|
||||||
"github.com/netbirdio/netbird/client/iface/bufsize"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -30,7 +30,7 @@ const (
|
|||||||
// WGEBPFProxy definition for proxy with EBPF support
|
// WGEBPFProxy definition for proxy with EBPF support
|
||||||
type WGEBPFProxy struct {
|
type WGEBPFProxy struct {
|
||||||
localWGListenPort int
|
localWGListenPort int
|
||||||
mtu int
|
mtu uint16
|
||||||
|
|
||||||
ebpfManager ebpfMgr.Manager
|
ebpfManager ebpfMgr.Manager
|
||||||
turnConnStore map[uint16]net.Conn
|
turnConnStore map[uint16]net.Conn
|
||||||
@@ -45,7 +45,7 @@ type WGEBPFProxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewWGEBPFProxy create new WGEBPFProxy instance
|
// NewWGEBPFProxy create new WGEBPFProxy instance
|
||||||
func NewWGEBPFProxy(wgPort int, mtu int) *WGEBPFProxy {
|
func NewWGEBPFProxy(wgPort int, mtu uint16) *WGEBPFProxy {
|
||||||
log.Debugf("instantiate ebpf proxy")
|
log.Debugf("instantiate ebpf proxy")
|
||||||
wgProxy := &WGEBPFProxy{
|
wgProxy := &WGEBPFProxy{
|
||||||
localWGListenPort: wgPort,
|
localWGListenPort: wgPort,
|
||||||
|
@@ -12,8 +12,8 @@ import (
|
|||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/iface/wgproxy/listener"
|
|
||||||
"github.com/netbirdio/netbird/client/iface/bufsize"
|
"github.com/netbirdio/netbird/client/iface/bufsize"
|
||||||
|
"github.com/netbirdio/netbird/client/iface/wgproxy/listener"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProxyWrapper help to keep the remoteConn instance for net.Conn.Close function call
|
// ProxyWrapper help to keep the remoteConn instance for net.Conn.Close function call
|
||||||
|
@@ -11,12 +11,12 @@ import (
|
|||||||
|
|
||||||
type KernelFactory struct {
|
type KernelFactory struct {
|
||||||
wgPort int
|
wgPort int
|
||||||
mtu int
|
mtu uint16
|
||||||
|
|
||||||
ebpfProxy *ebpf.WGEBPFProxy
|
ebpfProxy *ebpf.WGEBPFProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKernelFactory(wgPort int, mtu int) *KernelFactory {
|
func NewKernelFactory(wgPort int, mtu uint16) *KernelFactory {
|
||||||
f := &KernelFactory{
|
f := &KernelFactory{
|
||||||
wgPort: wgPort,
|
wgPort: wgPort,
|
||||||
mtu: mtu,
|
mtu: mtu,
|
||||||
|
@@ -9,10 +9,10 @@ import (
|
|||||||
// KernelFactory todo: check eBPF support on FreeBSD
|
// KernelFactory todo: check eBPF support on FreeBSD
|
||||||
type KernelFactory struct {
|
type KernelFactory struct {
|
||||||
wgPort int
|
wgPort int
|
||||||
mtu int
|
mtu uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKernelFactory(wgPort int, mtu int) *KernelFactory {
|
func NewKernelFactory(wgPort int, mtu uint16) *KernelFactory {
|
||||||
log.Infof("WireGuard Proxy Factory will produce UDP proxy")
|
log.Infof("WireGuard Proxy Factory will produce UDP proxy")
|
||||||
f := &KernelFactory{
|
f := &KernelFactory{
|
||||||
wgPort: wgPort,
|
wgPort: wgPort,
|
||||||
|
@@ -16,7 +16,7 @@ func TestProxyCloseByRemoteConnEBPF(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ebpfProxy := ebpf.NewWGEBPFProxy(51831)
|
ebpfProxy := ebpf.NewWGEBPFProxy(51831, 1280)
|
||||||
if err := ebpfProxy.Listen(); err != nil {
|
if err := ebpfProxy.Listen(); err != nil {
|
||||||
t.Fatalf("failed to initialize ebpf proxy: %s", err)
|
t.Fatalf("failed to initialize ebpf proxy: %s", err)
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,7 @@ func TestProxyCloseByRemoteConn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "linux" && os.Getenv("GITHUB_ACTIONS") != "true" {
|
if runtime.GOOS == "linux" && os.Getenv("GITHUB_ACTIONS") != "true" {
|
||||||
ebpfProxy := ebpf.NewWGEBPFProxy(51831)
|
ebpfProxy := ebpf.NewWGEBPFProxy(51831, 1280)
|
||||||
if err := ebpfProxy.Listen(); err != nil {
|
if err := ebpfProxy.Listen(); err != nil {
|
||||||
t.Fatalf("failed to initialize ebpf proxy: %s", err)
|
t.Fatalf("failed to initialize ebpf proxy: %s", err)
|
||||||
}
|
}
|
||||||
|
@@ -12,15 +12,14 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
cerrors "github.com/netbirdio/netbird/client/errors"
|
cerrors "github.com/netbirdio/netbird/client/errors"
|
||||||
"github.com/netbirdio/netbird/client/iface/wgproxy/listener"
|
|
||||||
"github.com/netbirdio/netbird/client/iface/bufsize"
|
"github.com/netbirdio/netbird/client/iface/bufsize"
|
||||||
|
"github.com/netbirdio/netbird/client/iface/wgproxy/listener"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// WGUDPProxy proxies
|
// WGUDPProxy proxies
|
||||||
type WGUDPProxy struct {
|
type WGUDPProxy struct {
|
||||||
localWGListenPort int
|
localWGListenPort int
|
||||||
mtu int
|
mtu uint16
|
||||||
|
|
||||||
remoteConn net.Conn
|
remoteConn net.Conn
|
||||||
localConn net.Conn
|
localConn net.Conn
|
||||||
@@ -37,7 +36,7 @@ type WGUDPProxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewWGUDPProxy instantiate a UDP based WireGuard proxy. This is not a thread safe implementation
|
// NewWGUDPProxy instantiate a UDP based WireGuard proxy. This is not a thread safe implementation
|
||||||
func NewWGUDPProxy(wgPort int, mtu int) *WGUDPProxy {
|
func NewWGUDPProxy(wgPort int, mtu uint16) *WGUDPProxy {
|
||||||
log.Debugf("Initializing new user space proxy with port %d", wgPort)
|
log.Debugf("Initializing new user space proxy with port %d", wgPort)
|
||||||
p := &WGUDPProxy{
|
p := &WGUDPProxy{
|
||||||
localWGListenPort: wgPort,
|
localWGListenPort: wgPort,
|
||||||
|
@@ -77,7 +77,7 @@ type ConfigInput struct {
|
|||||||
|
|
||||||
LazyConnectionEnabled *bool
|
LazyConnectionEnabled *bool
|
||||||
|
|
||||||
MTU *int
|
MTU *uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config Configuration type
|
// Config Configuration type
|
||||||
@@ -145,7 +145,7 @@ type Config struct {
|
|||||||
|
|
||||||
LazyConnectionEnabled bool
|
LazyConnectionEnabled bool
|
||||||
|
|
||||||
MTU int
|
MTU uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadConfig read config file and return with Config. If it is not exists create a new with default values
|
// ReadConfig read config file and return with Config. If it is not exists create a new with default values
|
||||||
|
@@ -467,12 +467,12 @@ func createEngineConfig(key wgtypes.Key, config *Config, peerConfig *mgmProto.Pe
|
|||||||
return engineConf, nil
|
return engineConf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectMTU(localMTU int, peerMTU int32) int {
|
func selectMTU(localMTU uint16, peerMTU int32) uint16 {
|
||||||
finalMTU := iface.DefaultMTU
|
var finalMTU uint16 = iface.DefaultMTU
|
||||||
if localMTU > 0 {
|
if localMTU > 0 {
|
||||||
finalMTU = localMTU
|
finalMTU = localMTU
|
||||||
} else if peerMTU > 0 {
|
} else if peerMTU > 0 {
|
||||||
finalMTU = int(peerMTU)
|
finalMTU = uint16(peerMTU)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set global DNS MTU
|
// Set global DNS MTU
|
||||||
|
@@ -25,9 +25,9 @@ import (
|
|||||||
"github.com/netbirdio/netbird/client/proto"
|
"github.com/netbirdio/netbird/client/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var currentMTU = iface.DefaultMTU
|
var currentMTU uint16 = iface.DefaultMTU
|
||||||
|
|
||||||
func SetCurrentMTU(mtu int) {
|
func SetCurrentMTU(mtu uint16) {
|
||||||
currentMTU = mtu
|
currentMTU = mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -124,7 +124,7 @@ type EngineConfig struct {
|
|||||||
|
|
||||||
LazyConnectionEnabled bool
|
LazyConnectionEnabled bool
|
||||||
|
|
||||||
MTU int
|
MTU uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// Engine is a mechanism responsible for reacting on Signal and Management stream events and managing connections to the remote peers.
|
// Engine is a mechanism responsible for reacting on Signal and Management stream events and managing connections to the remote peers.
|
||||||
|
@@ -429,7 +429,7 @@ func (s *Server) Login(callerCtx context.Context, msg *proto.LoginRequest) (*pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if msg.Mtu != nil {
|
if msg.Mtu != nil {
|
||||||
mtu := int(*msg.Mtu)
|
mtu := uint16(*msg.Mtu)
|
||||||
inputConfig.MTU = &mtu
|
inputConfig.MTU = &mtu
|
||||||
s.latestConfigInput.MTU = &mtu
|
s.latestConfigInput.MTU = &mtu
|
||||||
}
|
}
|
||||||
|
@@ -238,7 +238,7 @@ type serviceClient struct {
|
|||||||
RosenpassPermissive bool
|
RosenpassPermissive bool
|
||||||
interfaceName string
|
interfaceName string
|
||||||
interfacePort int
|
interfacePort int
|
||||||
mtu int
|
mtu uint16
|
||||||
networkMonitor bool
|
networkMonitor bool
|
||||||
disableDNS bool
|
disableDNS bool
|
||||||
disableClientRoutes bool
|
disableClientRoutes bool
|
||||||
@@ -427,7 +427,7 @@ func (s *serviceClient) getSettingsForm() *widget.Form {
|
|||||||
if s.managementURL != iMngURL || s.preSharedKey != s.iPreSharedKey.Text ||
|
if s.managementURL != iMngURL || s.preSharedKey != s.iPreSharedKey.Text ||
|
||||||
s.adminURL != iAdminURL || s.RosenpassPermissive != s.sRosenpassPermissive.Checked ||
|
s.adminURL != iAdminURL || s.RosenpassPermissive != s.sRosenpassPermissive.Checked ||
|
||||||
s.interfaceName != s.iInterfaceName.Text || s.interfacePort != int(port) ||
|
s.interfaceName != s.iInterfaceName.Text || s.interfacePort != int(port) ||
|
||||||
s.mtu != int(mtu) || s.networkMonitor != s.sNetworkMonitor.Checked ||
|
s.mtu != uint16(mtu) || s.networkMonitor != s.sNetworkMonitor.Checked ||
|
||||||
s.disableDNS != s.sDisableDNS.Checked ||
|
s.disableDNS != s.sDisableDNS.Checked ||
|
||||||
s.disableClientRoutes != s.sDisableClientRoutes.Checked ||
|
s.disableClientRoutes != s.sDisableClientRoutes.Checked ||
|
||||||
s.disableServerRoutes != s.sDisableServerRoutes.Checked ||
|
s.disableServerRoutes != s.sDisableServerRoutes.Checked ||
|
||||||
@@ -838,7 +838,7 @@ func (s *serviceClient) getSrvConfig() {
|
|||||||
s.RosenpassPermissive = cfg.RosenpassPermissive
|
s.RosenpassPermissive = cfg.RosenpassPermissive
|
||||||
s.interfaceName = cfg.InterfaceName
|
s.interfaceName = cfg.InterfaceName
|
||||||
s.interfacePort = int(cfg.WireguardPort)
|
s.interfacePort = int(cfg.WireguardPort)
|
||||||
s.mtu = int(cfg.Mtu)
|
s.mtu = uint16(cfg.Mtu)
|
||||||
|
|
||||||
s.networkMonitor = cfg.NetworkMonitor
|
s.networkMonitor = cfg.NetworkMonitor
|
||||||
s.disableDNS = cfg.DisableDns
|
s.disableDNS = cfg.DisableDns
|
||||||
|
@@ -5,9 +5,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/sharedsock"
|
|
||||||
"github.com/netbirdio/netbird/client/iface"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/netbirdio/netbird/client/iface"
|
||||||
|
"github.com/netbirdio/netbird/sharedsock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@@ -36,7 +36,7 @@ type SharedSocket struct {
|
|||||||
conn4 *socket.Conn
|
conn4 *socket.Conn
|
||||||
conn6 *socket.Conn
|
conn6 *socket.Conn
|
||||||
port int
|
port int
|
||||||
mtu int
|
mtu uint16
|
||||||
routerMux sync.RWMutex
|
routerMux sync.RWMutex
|
||||||
router routing.Router
|
router routing.Router
|
||||||
packetDemux chan rcvdPacket
|
packetDemux chan rcvdPacket
|
||||||
@@ -64,7 +64,7 @@ var writeSerializerOptions = gopacket.SerializeOptions{
|
|||||||
const maxIPUDPOverhead = 68
|
const maxIPUDPOverhead = 68
|
||||||
|
|
||||||
// Listen creates an IPv4 and IPv6 raw sockets, starts a reader and routing table routines
|
// Listen creates an IPv4 and IPv6 raw sockets, starts a reader and routing table routines
|
||||||
func Listen(port int, filter BPFFilter, mtu int) (_ net.PacketConn, err error) {
|
func Listen(port int, filter BPFFilter, mtu uint16) (_ net.PacketConn, err error) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
rawSock := &SharedSocket{
|
rawSock := &SharedSocket{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
@@ -9,6 +9,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Listen is not supported on other platforms then Linux
|
// Listen is not supported on other platforms then Linux
|
||||||
func Listen(port int, filter BPFFilter) (net.PacketConn, error) {
|
func Listen(port int, filter BPFFilter, mtu uint16) (net.PacketConn, error) {
|
||||||
return nil, fmt.Errorf("not supported OS %s. SharedSocket is only supported on Linux", runtime.GOOS)
|
return nil, fmt.Errorf("not supported OS %s. SharedSocket is only supported on Linux", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user