Skip to content

Commit

Permalink
Merge pull request #19 from freifunkMUC/feature/add-mtu-config
Browse files Browse the repository at this point in the history
allow setting the MTU on an interface
  • Loading branch information
fbuetler authored Jul 19, 2023
2 parents 7545570 + f9d700c commit 484603c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/wgembed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type IfaceConfig struct {
Address []string
ListenPort *int
DNS []string
MTU *int
}

type PeerConfig struct {
Expand Down
7 changes: 6 additions & 1 deletion pkg/wgembed/iface_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.zx2c4.com/wireguard/device"
)

// NewWithOpts creates a new network interface, needs to be enabled with WireGuardInterface.Up() afterwards.
Expand Down Expand Up @@ -36,7 +37,11 @@ func (wg *commonInterface) Up() error {
return errors.Wrap(err, "failed to bring wireguard interface up")
}

if err := netlink.LinkSetMTU(link, 1420); err != nil {
MTU := device.DefaultMTU
if wg.config.Interface.MTU != nil {
MTU = *wg.config.Interface.MTU
}
if err := netlink.LinkSetMTU(link, MTU); err != nil {
return errors.Wrap(err, "failed to set wireguard mtu")
}

Expand Down

0 comments on commit 484603c

Please sign in to comment.