Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MTU flag for vpn up #198

Merged
merged 1 commit into from
Dec 9, 2024
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
3 changes: 2 additions & 1 deletion src/cmd/vpnUp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func vpnUpCmd() *cmdBuilder.Cmd {
Short(i18n.T(i18n.CmdDescVpnUp)).
ScopeLevel(scope.Project).
Arg(scope.ProjectArgName, cmdBuilder.OptionalArg()).
IntFlag("mtu", 1420, i18n.T(i18n.VpnMtuFlag)).
BoolFlag("auto-disconnect", false, i18n.T(i18n.VpnAutoDisconnectFlag)).
HelpFlag(i18n.T(i18n.CmdHelpVpnUp)).
LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error {
Expand Down Expand Up @@ -98,7 +99,7 @@ func vpnUpCmd() *cmdBuilder.Cmd {
}
defer f.Close()

err = wg.GenerateConfig(f, privateKey, vpnSettings)
err = wg.GenerateConfig(f, privateKey, vpnSettings, cmdData.Params.GetInt("mtu"))
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ at https://docs.zerops.io/references/cli for further details.`,
ServiceIdFlag: "If you have access to more than one service, you must specify the service ID for which the\ncommand is to be executed.",
ProjectIdFlag: "If you have access to more than one project, you must specify the project ID for which the\ncommand is to be executed.",
VpnAutoDisconnectFlag: "If set, zCLI will automatically disconnect from the VPN if it is already connected.",
VpnMtuFlag: "If set, Wireguard interface will use this value for MTU. If VPN is not working, try a lower value.",
ZeropsYamlSetup: "Choose setup to be used from zerops.yml.",

// archiveClient
Expand Down
1 change: 1 addition & 0 deletions src/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ const (
ServiceIdFlag = "ServiceIdFlag"
ProjectIdFlag = "ProjectIdFlag"
VpnAutoDisconnectFlag = "VpnAutoDisconnectFlag"
VpnMtuFlag = "VpnMtuFlag"
ZeropsYamlSetup = "ZeropsYamlSetup"

// archiveClient
Expand Down
5 changes: 3 additions & 2 deletions src/wg/darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func CheckWgInstallation() error {
return nil
}

func GenerateConfig(f io.Writer, privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem) error {
data, err := defaultTemplateData(privateKey, vpnSettings)
func GenerateConfig(f io.Writer, privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem, mtu int) error {
data, err := defaultTemplateData(privateKey, vpnSettings, mtu)
if err != nil {
return err
}
Expand All @@ -46,6 +46,7 @@ func DownCmd(ctx context.Context, filePath, _ string) (err *cmdRunner.ExecCmd) {
var vpnTmpl = `
[Interface]
PrivateKey = {{.PrivateKey}}
MTU = {{.Mtu}}

Address = {{if .AssignedIpv4Address}}{{.AssignedIpv4Address}}/32{{end}}, {{.AssignedIpv6Address}}/128
PostUp = mkdir -p /etc/resolver
Expand Down
5 changes: 3 additions & 2 deletions src/wg/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func CheckWgInstallation() error {
return nil
}

func GenerateConfig(f io.Writer, privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem) error {
data, err := defaultTemplateData(privateKey, vpnSettings)
func GenerateConfig(f io.Writer, privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem, mtu int) error {
data, err := defaultTemplateData(privateKey, vpnSettings, mtu)
if err != nil {
return err
}
Expand All @@ -47,6 +47,7 @@ func DownCmd(ctx context.Context, filePath, _ string) (err *cmdRunner.ExecCmd) {
var vpnTmpl = `
[Interface]
PrivateKey = {{.PrivateKey}}
MTU = {{.Mtu}}

Address = {{if .AssignedIpv4Address}}{{.AssignedIpv4Address}}/32{{end}}, {{.AssignedIpv6Address}}/128
PostUp = resolvectl dns %i {{.Ipv4NetworkGateway}}
Expand Down
4 changes: 3 additions & 1 deletion src/wg/wg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package wg

import (
"net"
"strconv"

"github.com/pkg/errors"
"github.com/zeropsio/zerops-go/dto/output"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)

func defaultTemplateData(privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem) (map[string]string, error) {
func defaultTemplateData(privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem, mtu int) (map[string]string, error) {
projectIpv4Network := ""
if vpnSettings.Project.Ipv4.Network.Network != "" {
_, n, err := net.ParseCIDR(string(vpnSettings.Project.Ipv4.Network.Network))
Expand Down Expand Up @@ -46,6 +47,7 @@ func defaultTemplateData(privateKey wgtypes.Key, vpnSettings output.ProjectVpnIt
}

return map[string]string{
"Mtu": strconv.Itoa(mtu),
"PrivateKey": privateKey.String(),
"PublicKey": string(vpnSettings.Project.PublicKey),
"AssignedIpv4Address": string(vpnSettings.Peer.Ipv4.AssignedIpAddress),
Expand Down
5 changes: 3 additions & 2 deletions src/wg/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func CheckWgInstallation() error {
return nil
}

func GenerateConfig(f io.Writer, privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem) error {
data, err := defaultTemplateData(privateKey, vpnSettings)
func GenerateConfig(f io.Writer, privateKey wgtypes.Key, vpnSettings output.ProjectVpnItem, mtu int) error {
data, err := defaultTemplateData(privateKey, vpnSettings, mtu)
if err != nil {
return err
}
Expand Down Expand Up @@ -117,6 +117,7 @@ func DownCmd(ctx context.Context, _, interfaceName string) (err *cmdRunner.ExecC
var vpnTmpl = `
[Interface]
PrivateKey = {{.PrivateKey}}
MTU = {{.Mtu}}

Address = {{if .AssignedIpv4Address}}{{.AssignedIpv4Address}}/32{{end}}, {{.AssignedIpv6Address}}/128
DNS = {{.Ipv4NetworkGateway}}, zerops
Expand Down
Loading