more fun with linux ethernet taps

older kernels: must set MTU before IFF_UP.
newer kernels: must set MTU *after* IFF_UP
This commit is contained in:
Grant Limberg 2022-02-17 09:26:53 -08:00
parent ed74ed6ed2
commit 31c12aebb5
No known key found for this signature in database
GPG Key ID: 8F2F97D3BE8D7735

View File

@ -246,14 +246,19 @@ 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);
}
usleep(100000);
ifr.ifr_flags |= IFF_MULTICAST;
ifr.ifr_flags |= IFF_UP;