From 31c12aebb5be97e8509e8fcbb7b8599ebe28800f Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 17 Feb 2022 09:26:53 -0800 Subject: [PATCH] more fun with linux ethernet taps older kernels: must set MTU before IFF_UP. newer kernels: must set MTU *after* IFF_UP --- osdep/LinuxEthernetTap.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/osdep/LinuxEthernetTap.cpp b/osdep/LinuxEthernetTap.cpp index 9a178e26b..1192ffa90 100644 --- a/osdep/LinuxEthernetTap.cpp +++ b/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) {