فهرست منبع

Improve tun activation error messages

Nate Brown 5 سال پیش
والد
کامیت
5cad6a2ce3
1فایلهای تغییر یافته به همراه8 افزوده شده و 8 حذف شده
  1. 8 8
      tun_linux.go

+ 8 - 8
tun_linux.go

@@ -168,43 +168,43 @@ func (c Tun) Activate() error {
 
 	// Set the device ip address
 	if err = ioctl(fd, syscall.SIOCSIFADDR, uintptr(unsafe.Pointer(&ifra))); err != nil {
-		return err
+		return fmt.Errorf("failed to set tun address: %s", err)
 	}
 
 	// Set the device network
 	ifra.Addr.Addr = mask
 	if err = ioctl(fd, syscall.SIOCSIFNETMASK, uintptr(unsafe.Pointer(&ifra))); err != nil {
-		return err
+		return fmt.Errorf("failed to set tun netmask: %s", err)
 	}
 
 	// Set the device name
 	ifrf := ifReq{Name: devName}
 	if err = ioctl(fd, syscall.SIOCGIFFLAGS, uintptr(unsafe.Pointer(&ifrf))); err != nil {
-		return err
+		return fmt.Errorf("failed to set tun device name: %s", err)
 	}
 
 	// Set the MTU on the device
 	ifm := ifreqMTU{Name: devName, MTU: c.MaxMTU}
 	if err = ioctl(fd, syscall.SIOCSIFMTU, uintptr(unsafe.Pointer(&ifm))); err != nil {
-		return err
+		return fmt.Errorf("failed to set tun mtu: %s", err)
 	}
 
 	// Set the transmit queue length
 	ifrq := ifreqQLEN{Name: devName, Value: c.TXQueueLen}
 	if err = ioctl(fd, syscall.SIOCSIFTXQLEN, uintptr(unsafe.Pointer(&ifrq))); err != nil {
-		return err
+		return fmt.Errorf("failed to set tun tx queue length: %s", err)
 	}
 
 	// Bring up the interface
 	ifrf.Flags = ifrf.Flags | syscall.IFF_UP
 	if err = ioctl(fd, syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifrf))); err != nil {
-		return err
+		return fmt.Errorf("failed to bring the tun device up: %s", err)
 	}
 
 	// Set the routes
 	link, err := netlink.LinkByName(c.Device)
 	if err != nil {
-		return err
+		return fmt.Errorf("failed to get tun device link: %s", err)
 	}
 
 	// Default route
@@ -242,7 +242,7 @@ func (c Tun) Activate() error {
 	// Run the interface
 	ifrf.Flags = ifrf.Flags | syscall.IFF_UP | syscall.IFF_RUNNING
 	if err = ioctl(fd, syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifrf))); err != nil {
-		return err
+		return fmt.Errorf("failed to run tun device: %s", err)
 	}
 
 	return nil