Make the MTU configurable

This commit is contained in:
kaiyou
2020-11-29 09:31:22 +01:00
parent 00bd0820f5
commit fd8b63c291
3 changed files with 6 additions and 4 deletions

View File

@ -18,6 +18,7 @@ type State struct {
client *wgctrl.Client
OverlayAddr net.IPNet
Port int
Mtu int
PrivKey wgtypes.Key
PubKey wgtypes.Key
}
@ -25,7 +26,7 @@ type State struct {
// New creates a new Wesher Wireguard state
// The Wireguard keys are generated for every new interface
// The interface must later be setup using SetUpInterface
func New(iface string, port int, ipnet *net.IPNet, name string) (*State, *common.Node, error) {
func New(iface string, port int, mtu int, ipnet *net.IPNet, name string) (*State, *common.Node, error) {
client, err := wgctrl.New()
if err != nil {
return nil, nil, errors.Wrap(err, "could not instantiate wireguard client")
@ -41,6 +42,7 @@ func New(iface string, port int, ipnet *net.IPNet, name string) (*State, *common
iface: iface,
client: client,
Port: port,
Mtu: mtu,
PrivKey: privKey,
PubKey: pubKey,
}
@ -123,8 +125,7 @@ func (s *State) SetUpInterface(nodes []common.Node, routedNet *net.IPNet) error
}); err != nil {
return errors.Wrapf(err, "could not set address for %s", s.iface)
}
// TODO: make MTU configurable?
if err := netlink.LinkSetMTU(link, 1420); err != nil {
if err := netlink.LinkSetMTU(link, s.Mtu-80); err != nil {
return errors.Wrapf(err, "could not set MTU for %s", s.iface)
}
if err := netlink.LinkSetUp(link); err != nil {