mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-02 16:52:49 +00:00
mimic BSDEthernetTap but with creating/destroying char tap device
This commit is contained in:
parent
218ace51a7
commit
9a2310395d
@ -115,7 +115,8 @@ NetBSDEthernetTap::NetBSDEthernetTap(
|
|||||||
|
|
||||||
// On NetBSD there are /dev/tap{0..3} pre-created and for a moment I will stick with only them
|
// On NetBSD there are /dev/tap{0..3} pre-created and for a moment I will stick with only them
|
||||||
std::vector<std::string> devFiles(OSUtils::listDirectory("/dev"));
|
std::vector<std::string> devFiles(OSUtils::listDirectory("/dev"));
|
||||||
for(int i=0;i<4;++i) {
|
// for(int i=0;i<4;++i) {
|
||||||
|
for(int i=9993;i<(9993+128);++i) {
|
||||||
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||||
//if (std::find(devFiles.begin(),devFiles.end(),std::string(tmpdevname)) == devFiles.end()) {
|
//if (std::find(devFiles.begin(),devFiles.end(),std::string(tmpdevname)) == devFiles.end()) {
|
||||||
@ -128,6 +129,20 @@ NetBSDEthernetTap::NetBSDEthernetTap(
|
|||||||
::waitpid(cpid,&exitcode,0);
|
::waitpid(cpid,&exitcode,0);
|
||||||
} else throw std::runtime_error("fork() failed");
|
} else throw std::runtime_error("fork() failed");
|
||||||
|
|
||||||
|
cpid = (long)vfork();
|
||||||
|
if (cpid == 0) {
|
||||||
|
string tmp;
|
||||||
|
sprintf((char*)tmp.c_str(), "%d", i);
|
||||||
|
string minor = tmp.c_str();
|
||||||
|
::execl("/sbin/mknod","/sbin/mknod",devpath,"c","169",minor.c_str(),(const char *)0); //major 169 => tap
|
||||||
|
::_exit(-1);
|
||||||
|
} else if (cpid > 0) {
|
||||||
|
int exitcode = -1;
|
||||||
|
::waitpid(cpid,&exitcode,0);
|
||||||
|
} else throw std::runtime_error("fork() failed");
|
||||||
|
|
||||||
|
cerr<<"created device "<<devpath<<endl;
|
||||||
|
|
||||||
_dev = tmpdevname;
|
_dev = tmpdevname;
|
||||||
_fd = ::open( devpath,O_RDWR);
|
_fd = ::open( devpath,O_RDWR);
|
||||||
if (!stat(devpath,&stattmp)) {
|
if (!stat(devpath,&stattmp)) {
|
||||||
@ -219,6 +234,17 @@ NetBSDEthernetTap::~NetBSDEthernetTap()
|
|||||||
int exitcode = -1;
|
int exitcode = -1;
|
||||||
::waitpid(cpid,&exitcode,0);
|
::waitpid(cpid,&exitcode,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpid = (long)vfork();
|
||||||
|
if (cpid == 0) {
|
||||||
|
string tmp="/dev/";
|
||||||
|
tmp+=_dev.c_str();
|
||||||
|
::execl("/bin/rm","/bin/rm",tmp.c_str(),(const char *)0);
|
||||||
|
::_exit(-1);
|
||||||
|
} else if (cpid > 0) {
|
||||||
|
int exitcode = -1;
|
||||||
|
::waitpid(cpid,&exitcode,0);
|
||||||
|
} else throw std::runtime_error("fork() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetBSDEthernetTap::setEnabled(bool en)
|
void NetBSDEthernetTap::setEnabled(bool en)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user