Skip to content

Commit

Permalink
try to make setting up MTU on linux better
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDoanRivian committed Sep 22, 2024
1 parent ada3b72 commit 8e9072d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions overlay/tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,21 @@ func (t *tun) Activate() error {
return fmt.Errorf("failed to bring the tun device up: %s", err)
}

// Run the interface
ifrf.Flags = ifrf.Flags | unix.IFF_UP | unix.IFF_RUNNING
if err = ioctl(t.ioctlFd, unix.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifrf))); err != nil {
return fmt.Errorf("failed to run tun device: %s", err)
}

//set route MTU
for i := range t.vpnNetworks {
if err = t.setDefaultRoute(t.vpnNetworks[i]); err != nil {
return fmt.Errorf("failed to set default route MTU: %w", err)
//todo why does this only work sometimes?
//avoid crashing for now
t.l.WithError(err).Error("failed to set default route MTU")
}
}

// Run the interface
ifrf.Flags = ifrf.Flags | unix.IFF_UP | unix.IFF_RUNNING
if err = ioctl(t.ioctlFd, unix.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifrf))); err != nil {
return fmt.Errorf("failed to run tun device: %s", err)
}

// Set the routes
if err = t.addRoutes(false); err != nil {
return err
Expand All @@ -401,7 +403,6 @@ func (t *tun) setMTU() {

func (t *tun) setDefaultRoute(cidr netip.Prefix) error {
// Default route

dr := &net.IPNet{
IP: cidr.Masked().Addr().AsSlice(),
Mask: net.CIDRMask(cidr.Bits(), cidr.Addr().BitLen()),
Expand Down

0 comments on commit 8e9072d

Please sign in to comment.