Browse Source

more fun with linux ethernet taps

older kernels: must set MTU before IFF_UP.
newer kernels: must set MTU *after* IFF_UP
Grant Limberg 3 năm trước cách đây
mục cha
commit
31c12aebb5
1 tập tin đã thay đổi với 12 bổ sung7 xóa
  1. 12 7
      osdep/LinuxEthernetTap.cpp

+ 12 - 7
osdep/LinuxEthernetTap.cpp

@@ -246,15 +246,20 @@ LinuxEthernetTap::LinuxEthernetTap(
 			return;
 		}
 
-		ifr.ifr_ifru.ifru_mtu = (int)_mtu;
-		if (ioctl(sock,SIOCSIFMTU,(void *)&ifr) < 0) {
-			::close(sock);
-			printf("WARNING: ioctl() failed setting up Linux tap device (set MTU)\n");
-			return;
-		}
-
 		usleep(100000);
 
+		if (isOldLinuxKernel()) {
+			ifr.ifr_ifru.ifru_mtu = (int)_mtu;
+			if (ioctl(sock,SIOCSIFMTU,(void *)&ifr) < 0) {
+				::close(sock);
+				printf("WARNING: ioctl() failed setting up Linux tap device (set MTU)\n");
+				return;
+			}
+
+			usleep(100000);
+		}
+	
+
 		ifr.ifr_flags |= IFF_MULTICAST;
 		ifr.ifr_flags |= IFF_UP;
 		if (ioctl(sock,SIOCSIFFLAGS,(void *)&ifr) < 0) {