Skip to content

Commit 6e9f4cf

Browse files
committed
fix: fixes after proper testing
1 parent 71919f0 commit 6e9f4cf

File tree

9 files changed

+63
-31
lines changed

9 files changed

+63
-31
lines changed

client/iface/device/device_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ type TunDevice struct {
2929
filteredDevice *FilteredDevice
3030
udpMux *udpmux.UniversalUDPMuxDefault
3131
configurer WGConfigurer
32-
amneziaConfig AmneziaConfig
32+
amneziaConfig configurer.AmneziaConfig
3333
}
3434

35-
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind, amneziaConfig AmneziaConfig) *TunDevice {
35+
func NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind, amneziaConfig configurer.AmneziaConfig) *TunDevice {
3636
return &TunDevice{
3737
name: name,
3838
address: address,

client/iface/device/kernel_module.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
package device
44

5+
import "github.com/netbirdio/netbird/client/internal/amneziawg"
6+
57
// WireGuardModuleIsLoaded check if we can load WireGuard mod (linux only)
6-
func WireGuardModuleIsLoaded() bool {
8+
func WireGuardModuleIsLoaded(conf amneziawg.AmneziaConfig) bool {
79
return false
810
}

client/iface/device/kernel_module_freebsd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package device
22

3+
import "github.com/netbirdio/netbird/client/internal/amneziawg"
4+
35
// WireGuardModuleIsLoaded check if kernel support wireguard
4-
func WireGuardModuleIsLoaded() bool {
6+
func WireGuardModuleIsLoaded(conf amneziawg.AmneziaConfig) bool {
57
// Despite the fact FreeBSD natively support Wireguard (https://github.com/WireGuard/wireguard-freebsd)
68
// we are currently do not use it, since it is required to add wireguard kernel support to
79
// - https://github.com/netbirdio/netbird/tree/main/sharedsock

client/iface/device/kernel_module_linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strings"
1616
"syscall"
1717

18+
"github.com/netbirdio/netbird/client/internal/amneziawg"
1819
log "github.com/sirupsen/logrus"
1920
"github.com/vishvananda/netlink"
2021
"golang.org/x/sys/unix"
@@ -85,14 +86,14 @@ func ModuleTunIsLoaded() bool {
8586
}
8687

8788
// WireGuardModuleIsLoaded check if we can load WireGuard mod (linux only)
88-
func WireGuardModuleIsLoaded() bool {
89+
func WireGuardModuleIsLoaded(conf amneziawg.AmneziaConfig) bool {
8990

9091
if os.Getenv(envDisableWireGuardKernel) == "true" {
9192
log.Debugf("WireGuard kernel module disabled because the %s env is set to true", envDisableWireGuardKernel)
9293
return false
9394
}
9495

95-
useAmnezia := os.Getenv(envUseAmneziaWireGuardKernel) == "true"
96+
useAmnezia := !conf.IsEmpty()
9697
if !useAmnezia && canCreateFakeWireGuardInterface() {
9798
return true
9899
}

client/iface/iface_new_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewWGIFace(opts WGIFaceOpts) (*WGIface, error) {
2929
return wgIFace, nil
3030
}
3131

32-
if device.WireGuardModuleIsLoaded() {
32+
if device.WireGuardModuleIsLoaded(opts.AmneziaConfig) {
3333
wgIFace.tun = device.NewKernelDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, opts.MTU, opts.TransportNet)
3434
wgIFace.wgProxyFactory = wgproxy.NewKernelFactory(opts.WGPort, opts.MTU)
3535
return wgIFace, nil

client/iface/iface_new_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func NewWGIFace(opts WGIFaceOpts) (*WGIface, error) {
1818

1919
var tun WGTunDevice
2020
if netstack.IsEnabled() {
21-
tun = device.NewNetstackDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, opts.MTU, iceBind, netstack.ListenAddr())
21+
tun = device.NewNetstackDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, opts.MTU, iceBind, netstack.ListenAddr(), opts.AmneziaConfig)
2222
} else {
23-
tun = device.NewTunDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, opts.MTU, iceBind)
23+
tun = device.NewTunDevice(opts.IFaceName, wgAddress, opts.WGPort, opts.WGPrivKey, opts.MTU, iceBind, opts.AmneziaConfig)
2424
}
2525

2626
wgIFace := &WGIface{

client/internal/amneziawg/amneziawg.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package amneziawg
22

3+
import "github.com/netbirdio/netbird/shared/management/proto"
4+
35
// AmneziaConfig describes AmneziaWG obfuscation parameters.
46
// If nil or all fields are zero, it behaves as standard WireGuard.
57
type AmneziaConfig struct {
@@ -21,10 +23,20 @@ type AmneziaConfig struct {
2123

2224
func (cfg AmneziaConfig) IsEmpty() bool {
2325

24-
return cfg.Jc == 0 && cfg.Jmin == 0 && cfg.Jmax == 0 &&
25-
cfg.S1 == 0 && cfg.S2 == 0 &&
26-
cfg.H1 == 0 && cfg.H2 == 0 && cfg.H3 == 0 && cfg.H4 == 0 &&
27-
cfg.I1 == "" && cfg.I2 == "" && cfg.I3 == "" && cfg.I4 == "" && cfg.I5 == ""
26+
return cfg.Jc == 0 &&
27+
cfg.Jmin == 0 &&
28+
cfg.Jmax == 0 &&
29+
cfg.S1 == 0 &&
30+
cfg.S2 == 0 &&
31+
cfg.H1 == 0 &&
32+
cfg.H2 == 0 &&
33+
cfg.H3 == 0 &&
34+
cfg.H4 == 0 &&
35+
cfg.I1 == "" &&
36+
cfg.I2 == "" &&
37+
cfg.I3 == "" &&
38+
cfg.I4 == "" &&
39+
cfg.I5 == ""
2840
}
2941
func (cfg AmneziaConfig) GetJc() int32 { return cfg.Jc }
3042
func (cfg AmneziaConfig) GetJmin() int32 { return cfg.Jmin }
@@ -40,3 +52,24 @@ func (cfg AmneziaConfig) GetI2() string { return cfg.I2 }
4052
func (cfg AmneziaConfig) GetI3() string { return cfg.I3 }
4153
func (cfg AmneziaConfig) GetI4() string { return cfg.I4 }
4254
func (cfg AmneziaConfig) GetI5() string { return cfg.I5 }
55+
56+
func FromProtobuf(config *proto.AmneziaConfig) AmneziaConfig {
57+
58+
return AmneziaConfig{
59+
Jc: *config.Jc,
60+
Jmin: *config.Jmin,
61+
Jmax: *config.Jmax,
62+
S1: *config.S1,
63+
S2: *config.S2,
64+
H1: *config.H1,
65+
H2: *config.H2,
66+
H3: *config.H3,
67+
H4: *config.H4,
68+
I1: *config.I1,
69+
I2: *config.I2,
70+
I3: *config.I3,
71+
I4: *config.I4,
72+
I5: *config.I5,
73+
}
74+
75+
}

client/internal/connect.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (c *ConnectClient) run(mobileDependency MobileDependency, runningChan chan
209209
localPeerState := peer.LocalPeerState{
210210
IP: loginResp.GetPeerConfig().GetAddress(),
211211
PubKey: myPrivateKey.PublicKey().String(),
212-
KernelInterface: device.WireGuardModuleIsLoaded(),
212+
KernelInterface: false, // do not load kernel interface by default, as it could brake amneziaWG
213213
FQDN: loginResp.GetPeerConfig().GetFqdn(),
214214
}
215215
c.statusRecorder.UpdateLocalPeerState(localPeerState)
@@ -446,22 +446,16 @@ func createEngineConfig(key wgtypes.Key, config *profilemanager.Config, peerConf
446446
LazyConnectionEnabled: config.LazyConnectionEnabled,
447447

448448
MTU: selectMTU(config.MTU, peerConfig.Mtu),
449-
AmneziaConfig: amneziawg.AmneziaConfig{
450-
Jc: *peerConfig.AmneziaConfig.Jc,
451-
Jmin: *peerConfig.AmneziaConfig.Jmin,
452-
Jmax: *peerConfig.AmneziaConfig.Jmax,
453-
S1: *peerConfig.AmneziaConfig.S1,
454-
S2: *peerConfig.AmneziaConfig.S2,
455-
H1: *peerConfig.AmneziaConfig.H1,
456-
H2: *peerConfig.AmneziaConfig.H2,
457-
H3: *peerConfig.AmneziaConfig.H3,
458-
H4: *peerConfig.AmneziaConfig.H4,
459-
I1: *peerConfig.AmneziaConfig.I1,
460-
I2: *peerConfig.AmneziaConfig.I2,
461-
I3: *peerConfig.AmneziaConfig.I3,
462-
I4: *peerConfig.AmneziaConfig.I4,
463-
I5: *peerConfig.AmneziaConfig.I5,
464-
},
449+
}
450+
451+
if peerConfig.AmneziaConfig != nil {
452+
453+
engineConf.AmneziaConfig = amneziawg.FromProtobuf(peerConfig.AmneziaConfig)
454+
log.Infof("Init amneziaWG config from peer: %v", engineConf.AmneziaConfig)
455+
} else {
456+
457+
engineConf.AmneziaConfig = amneziawg.AmneziaConfig{}
458+
log.Infof("Init empty amneziaWG config")
465459
}
466460

467461
if config.PreSharedKey != "" {

client/internal/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ func (e *Engine) updateConfig(conf *mgmProto.PeerConfig) error {
941941
state := e.statusRecorder.GetLocalPeerState()
942942
state.IP = e.wgInterface.Address().String()
943943
state.PubKey = e.config.WgPrivateKey.PublicKey().String()
944-
state.KernelInterface = device.WireGuardModuleIsLoaded()
944+
state.KernelInterface = device.WireGuardModuleIsLoaded(amneziawg.FromProtobuf(conf.AmneziaConfig))
945945
state.FQDN = conf.GetFqdn()
946946

947947
e.statusRecorder.UpdateLocalPeerState(state)

0 commit comments

Comments
 (0)