Skip to content

Commit ba07d1f

Browse files
cleanup
1 parent 9a23103 commit ba07d1f

File tree

4 files changed

+19
-36
lines changed

4 files changed

+19
-36
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ For Mac, Linux, and BSD, just type "make" (or "gmake" on BSD). You won't need mu
3737

3838
* **Mac**: Xcode command line tools. It should build on OSX 10.7 or newer.
3939
* **Linux**: gcc/g++ (4.9 or newer recommended) or clang/clang++ (3.4 or newer recommended) Makefile will use clang by default if available. The Linux build will auto-detect the presence of development headers for *json-parser*, *http-parser*, *li8bnatpmp*, and *libminiupnpc* and will link against the system libraries for these if they are present and recent enough. Otherwise the bundled versions in [ext/](ext/) will be used. Type `make install` to install the binaries and other files on the system, though this will not create init.d or systemd links.
40-
* **FreeBSD**: C++ compiler (G++ usually) and GNU make (gmake).
40+
* **FreeBSD/OpenBSD/NetBSD**: C++ compiler (G++ usually) and GNU make (gmake).
4141

4242
Each supported platform has its own *make-XXX.mk* file that contains the actual make rules for the platform. The right .mk file is included by the main Makefile based on the GNU make *OSTYPE* variable. Take a look at the .mk file for your platform for other targets, debug build rules, etc.
4343

osdep/NetBSDEthernetTap.cpp

+8-35
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,17 @@ NetBSDEthernetTap::NetBSDEthernetTap(
9191
char devpath[64],ethaddr[64],mtustr[32],metstr[32],tmpdevname[32];
9292
struct stat stattmp;
9393

94-
// On FreeBSD at least we can rename, so use nwid to generate a deterministic unique zt#### name using base32
95-
// As a result we don't use desiredDevice
96-
_dev = "zt";
97-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 60) & 0x1f)]);
98-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 55) & 0x1f)]);
99-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 50) & 0x1f)]);
100-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 45) & 0x1f)]);
101-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 40) & 0x1f)]);
102-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 35) & 0x1f)]);
103-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 30) & 0x1f)]);
104-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 25) & 0x1f)]);
105-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 20) & 0x1f)]);
106-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 15) & 0x1f)]);
107-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 10) & 0x1f)]);
108-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 5) & 0x1f)]);
109-
_dev.push_back(ZT_BASE32_CHARS[(unsigned long)(nwid & 0x1f)]);
110-
11194
Mutex::Lock _gl(globalTapCreateLock);
11295

11396
if (mtu > 2800)
11497
throw std::runtime_error("max tap MTU is 2800");
11598

116-
// On NetBSD there are /dev/tap{0..3} pre-created and for a moment I will stick with only them
99+
// we can create /dev/tap*
117100
std::vector<std::string> devFiles(OSUtils::listDirectory("/dev"));
118-
// for(int i=0;i<4;++i) {
119101
for(int i=9993;i<(9993+128);++i) {
120102
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
121103
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
122-
//if (std::find(devFiles.begin(),devFiles.end(),std::string(tmpdevname)) == devFiles.end()) {
104+
if (std::find(devFiles.begin(),devFiles.end(),std::string(tmpdevname)) == devFiles.end()) {
123105
long cpid = (long)vfork();
124106
if (cpid == 0) {
125107
::execl("/sbin/ifconfig","/sbin/ifconfig",tmpdevname,"create",(const char *)0);
@@ -134,7 +116,9 @@ NetBSDEthernetTap::NetBSDEthernetTap(
134116
string tmp;
135117
sprintf((char*)tmp.c_str(), "%d", i);
136118
string minor = tmp.c_str();
137-
::execl("/sbin/mknod","/sbin/mknod",devpath,"c","169",minor.c_str(),(const char *)0); //major 169 => tap
119+
::execl("/sbin/mknod","/sbin/mknod",devpath,"c","169",minor.c_str(),(const char *)0);
120+
// http://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/conf/majors
121+
// major 169 => tap
138122
::_exit(-1);
139123
} else if (cpid > 0) {
140124
int exitcode = -1;
@@ -146,25 +130,14 @@ NetBSDEthernetTap::NetBSDEthernetTap(
146130
_dev = tmpdevname;
147131
_fd = ::open( devpath,O_RDWR);
148132
if (!stat(devpath,&stattmp)) {
149-
/*cpid = (long)vfork();
150-
if (cpid == 0) {
151-
::execl("/sbin/ifconfig","/sbin/ifconfig",tmpdevname,"name",_dev.c_str(),(const char *)0);
152-
::_exit(-1);
153-
} else if (cpid > 0) {
154-
int exitcode = -1;
155-
::waitpid(cpid,&exitcode,0);
156-
if (exitcode)
157-
throw std::runtime_error("ifconfig rename operation failed");
158-
} else throw std::runtime_error("fork() failed");*/
159-
160-
161133
if (_fd > 0)
162134
break;
163-
//else throw std::runtime_error("unable to open created tap device ");
135+
else
136+
throw std::runtime_error("unable to open created tap device ");
164137
} else {
165138
throw std::runtime_error("cannot find /dev node for newly created tap device");
166139
}
167-
//}
140+
}
168141
}
169142

170143
if (_fd <= 0)

osdep/freebsd_getifmaddrs.c

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
this BSD licensed code is from https://github.com/freebsd/freebsd/blob/386ddae58459341ec567604707805814a2128a57/lib/libc/net/getifmaddrs.c
3+
as in older OS X there is no getifmaddrs() and related functions is NetBSD
4+
*/
5+
16
#define NET_RT_IFMALIST 4 /* return multicast address list */
27
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
38

osdep/freebsd_getifmaddrs.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
this BSD code is from https://github.com/freebsd/freebsd/blob/386ddae58459341ec567604707805814a2128a57/include/ifaddrs.h
3+
as in older OS X there is no getifmaddrs() and related functions is NetBSD
4+
*/
5+
16
/* $FreeBSD$ */
27

38
/*

0 commit comments

Comments
 (0)