Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services/wireguard/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog/log"

nodeconfig "github.com/mysteriumnetwork/node/config"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/core/connection/connectionstate"
"github.com/mysteriumnetwork/node/core/ip"
Expand Down Expand Up @@ -173,6 +174,7 @@ func (c *Connection) start(ctx context.Context, start startConn, options connect
var conn wg.ConnectionEndpoint
conn, err = start(wgcfg.DeviceConfig{
IfaceName: "", // Interface name will be generated by connection endpoint.
MTU: nodeconfig.GetInt(nodeconfig.FlagWireguardMTU),
Subnet: config.Consumer.IPAddress,
PrivateKey: c.privateKey,
ListenPort: config.LocalPort,
Expand Down
11 changes: 10 additions & 1 deletion services/wireguard/endpoint/proxyclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func (c *client) ConfigureDevice(cfg wgcfg.DeviceConfig) error {
if err != nil {
return fmt.Errorf("could not parse DNS addr: %w", err)
}
tunnel, tnet, err := netstack.CreateNetTUN([]netip.Addr{localAddr}, []netip.Addr{dnsAddr}, device.DefaultMTU)
mtu := effectiveMTU(cfg.MTU)
log.Info().Int("mtu", mtu).Msg("Creating proxy-mode WireGuard netstack")
tunnel, tnet, err := netstack.CreateNetTUN([]netip.Addr{localAddr}, []netip.Addr{dnsAddr}, mtu)
if err != nil {
return fmt.Errorf("failed to create netstack device %s: %w", cfg.IfaceName, err)
}
Expand Down Expand Up @@ -94,6 +96,13 @@ func (c *client) ConfigureDevice(cfg wgcfg.DeviceConfig) error {
return nil
}

func effectiveMTU(configured int) int {
if configured > 0 {
return configured
}
return device.DefaultMTU
}

func (c *client) DestroyDevice(iface string) error {
return c.Close()
}
Expand Down
6 changes: 6 additions & 0 deletions services/wireguard/endpoint/proxyclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ import (

"github.com/mysteriumnetwork/node/services/wireguard/wgcfg"
"github.com/stretchr/testify/assert"
"golang.zx2c4.com/wireguard/device"
)

func TestEffectiveMTU(t *testing.T) {
assert.Equal(t, device.DefaultMTU, effectiveMTU(0))
assert.Equal(t, 1280, effectiveMTU(1280))
}

func Test_ConfigureDevice_ConfigureErrors(t *testing.T) {

client, err := New()
Expand Down
Loading