mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-22 02:16:38 +00:00
Merge pull request #1390 from jonathonf/linux-tap-link-ordering
Set MAC address before bringing up Linux TAP link
This commit is contained in:
commit
c69d2df0a2
@ -208,12 +208,6 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some kernel versions seem to require you to yield while the device comes up
|
|
||||||
// before they will accept MTU and MAC. For others it doesn't matter, but is
|
|
||||||
// harmless. This was moved to the worker thread though so as not to block the
|
|
||||||
// main ZeroTier loop.
|
|
||||||
usleep(500000);
|
|
||||||
|
|
||||||
ifr.ifr_ifru.ifru_hwaddr.sa_family = ARPHRD_ETHER;
|
ifr.ifr_ifru.ifru_hwaddr.sa_family = ARPHRD_ETHER;
|
||||||
_mac.copyTo(ifr.ifr_ifru.ifru_hwaddr.sa_data,6);
|
_mac.copyTo(ifr.ifr_ifru.ifru_hwaddr.sa_data,6);
|
||||||
if (ioctl(sock,SIOCSIFHWADDR,(void *)&ifr) < 0) {
|
if (ioctl(sock,SIOCSIFHWADDR,(void *)&ifr) < 0) {
|
||||||
@ -222,13 +216,6 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||||||
return;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ifr.ifr_flags |= IFF_UP;
|
ifr.ifr_flags |= IFF_UP;
|
||||||
if (ioctl(sock,SIOCSIFFLAGS,(void *)&ifr) < 0) {
|
if (ioctl(sock,SIOCSIFFLAGS,(void *)&ifr) < 0) {
|
||||||
::close(sock);
|
::close(sock);
|
||||||
@ -236,6 +223,19 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some kernel versions seem to require you to yield while the device comes up
|
||||||
|
// before they will accept MTU and MAC. For others it doesn't matter, but is
|
||||||
|
// harmless. This was moved to the worker thread though so as not to block the
|
||||||
|
// main ZeroTier loop.
|
||||||
|
usleep(500000);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
fcntl(_fd,F_SETFL,O_NONBLOCK);
|
fcntl(_fd,F_SETFL,O_NONBLOCK);
|
||||||
|
|
||||||
::close(sock);
|
::close(sock);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user