Skip to content

Commit cd19177

Browse files
committed
Add custom management plane for 3rd party vendors
1 parent 3e7aacf commit cd19177

8 files changed

+874
-9
lines changed

make-linux.mk

+16-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ DESTDIR?=
1616
EXTRA_DEPS?=
1717

1818
include objects.mk
19-
ONE_OBJS+=osdep/LinuxEthernetTap.o
20-
ONE_OBJS+=osdep/LinuxNetLink.o
19+
ifeq ($(ZT_EXTOSDEP),1)
20+
ONE_OBJS+=osdep/ExtOsdep.o
21+
override DEFS += -DZT_EXTOSDEP
22+
else
23+
ONE_OBJS+=osdep/LinuxEthernetTap.o
24+
ONE_OBJS+=osdep/LinuxNetLink.o
25+
endif
2126

2227
# for central controller buildsk
2328
TIMESTAMP=$(shell date +"%Y%m%d%H%M")
@@ -275,6 +280,10 @@ ifeq ($(CC_MACH),loongarch64)
275280
override DEFS+=-DZT_NO_TYPE_PUNNING
276281
endif
277282

283+
ifeq ($(ZT_EXTOSDEP), 1)
284+
ZT_SSO_SUPPORTED=0
285+
endif
286+
278287
# Fail if system architecture could not be determined
279288
ifeq ($(ZT_ARCHITECTURE),999)
280289
ERR=$(error FATAL: architecture could not be determined from $(CC) -dumpmachine: $(CC_MACH))
@@ -339,8 +348,11 @@ ifeq ($(ZT_ARCHITECTURE),3)
339348
override CXXFLAGS+=-march=armv5t -mfloat-abi=soft -msoft-float -mno-unaligned-access -marm
340349
ZT_USE_ARM32_NEON_ASM_CRYPTO=0
341350
else
342-
override CFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s
343-
override CXXFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -fexceptions -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s
351+
ifeq ($(ZT_EXTOSDEP), 0)
352+
override CFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s
353+
override CXXFLAGS+=-mfloat-abi=hard -march=armv6zk -marm -mfpu=vfp -fexceptions -mno-unaligned-access -mtp=cp15 -mcpu=arm1176jzf-s
354+
override DEFS+=-DZT_NO_PEER_METRICS
355+
endif
344356
ZT_USE_ARM32_NEON_ASM_CRYPTO=0
345357
endif
346358
endif

one.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <sys/socket.h>
5858
#include <ifaddrs.h>
5959
#include <sys/ioctl.h>
60+
#include "osdep/ExtOsdep.hpp"
6061
#ifndef ZT_NO_CAPABILITIES
6162
#include <linux/capability.h>
6263
#include <linux/securebits.h>
@@ -2110,15 +2111,30 @@ int main(int argc,char **argv)
21102111
signal(SIGQUIT,&_sighandlerQuit);
21112112
signal(SIGINT,&_sighandlerQuit);
21122113

2114+
#ifdef ZT_EXTOSDEP
2115+
int extosdepFd1 = -1;
2116+
int extosdepFd2 = -1;
2117+
for(int i=1;i<argc;++i) {
2118+
if (argv[i][0] != '-' || argv[i][1] != 'x') continue;
2119+
if (sscanf(argv[i] + 2, "%d,%d", &extosdepFd1, &extosdepFd2) == 2) break;
2120+
fprintf(stderr, "bad extosdepFd\n");
2121+
return 1;
2122+
}
2123+
#endif // ZT_EXTOSDEP
2124+
21132125
/* Ensure that there are no inherited file descriptors open from a previous
21142126
* incarnation. This is a hack to ensure that GitHub issue #61 or variants
21152127
* of it do not return, and should not do anything otherwise bad. */
21162128
{
21172129
int mfd = STDIN_FILENO;
21182130
if (STDOUT_FILENO > mfd) mfd = STDOUT_FILENO;
21192131
if (STDERR_FILENO > mfd) mfd = STDERR_FILENO;
2120-
for(int f=mfd+1;f<1024;++f)
2132+
for(int f=mfd+1;f<1024;++f) {
2133+
#ifdef ZT_EXTOSDEP
2134+
if (f == extosdepFd1 || f == extosdepFd2) continue;
2135+
#endif // ZT_EXTOSDEP
21212136
::close(f);
2137+
}
21222138
}
21232139

21242140
bool runAsDaemon = false;
@@ -2224,7 +2240,9 @@ int main(int argc,char **argv)
22242240
return 0;
22252241
} break;
22262242
#endif // __WINDOWS__
2227-
2243+
#ifdef ZT_EXTOSDEP
2244+
case 'x': break;
2245+
#endif
22282246
case 'h':
22292247
case '?':
22302248
default:
@@ -2354,6 +2372,15 @@ int main(int argc,char **argv)
23542372
}
23552373
#endif // __UNIX_LIKE__
23562374

2375+
#ifdef ZT_EXTOSDEP
2376+
if (extosdepFd1 < 0) {
2377+
fprintf(stderr, "no extosdepFd specified\n");
2378+
OSUtils::rm(pidPath.c_str());
2379+
return 1;
2380+
}
2381+
ExtOsdep::init(extosdepFd1, extosdepFd2);
2382+
#endif
2383+
23572384
_OneServiceRunner thr(argv[0],homeDir,port);
23582385
thr.threadMain();
23592386
//Thread::join(Thread::start(&thr));

osdep/Binder.hpp

+22
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "../node/Utils.hpp"
5454
#include "OSUtils.hpp"
5555
#include "Phy.hpp"
56+
#include "../osdep/ExtOsdep.hpp"
5657

5758
#include <algorithm>
5859
#include <atomic>
@@ -136,6 +137,25 @@ class Binder {
136137
bool interfacesEnumerated = true;
137138

138139
if (explicitBind.empty()) {
140+
#ifdef ZT_EXTOSDEP
141+
std::map<InetAddress,std::string> addrs;
142+
interfacesEnumerated = ExtOsdep::getBindAddrs(addrs);
143+
for (auto &a : addrs) {
144+
auto ip = a.first;
145+
switch(ip.ipScope()) {
146+
default: break;
147+
case InetAddress::IP_SCOPE_PSEUDOPRIVATE:
148+
case InetAddress::IP_SCOPE_GLOBAL:
149+
case InetAddress::IP_SCOPE_SHARED:
150+
case InetAddress::IP_SCOPE_PRIVATE:
151+
for(int x=0;x<(int)portCount;++x) {
152+
ip.setPort(ports[x]);
153+
localIfAddrs.insert(std::pair<InetAddress,std::string>(ip,a.second));
154+
}
155+
break;
156+
}
157+
}
158+
#else // ZT_EXTOSDEP
139159
#ifdef __WINDOWS__
140160

141161
char aabuf[32768];
@@ -386,6 +406,8 @@ class Binder {
386406
#endif
387407

388408
#endif
409+
410+
#endif // ZT_EXTOSDEP
389411
}
390412
else {
391413
for (std::vector<InetAddress>::const_iterator i(explicitBind.begin()); i != explicitBind.end(); ++i) {

osdep/EthernetTap.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#endif // __APPLE__
3333

3434
#ifdef __LINUX__
35+
#include "ExtOsdep.hpp"
3536
#include "LinuxEthernetTap.hpp"
3637
#endif // __LINUX__
3738

@@ -94,7 +95,11 @@ std::shared_ptr<EthernetTap> EthernetTap::newInstance(
9495
#endif // __APPLE__
9596

9697
#ifdef __LINUX__
98+
#ifdef ZT_EXTOSDEP
99+
return std::shared_ptr<EthernetTap>(new ExtOsdepTap(homePath,mac,mtu,metric,nwid,friendlyName,handler,arg));
100+
#else
97101
return std::shared_ptr<EthernetTap>(new LinuxEthernetTap(homePath,concurrency,pinning,mac,mtu,metric,nwid,friendlyName,handler,arg));
102+
#endif // ZT_EXTOSDEP
98103
#endif // __LINUX__
99104

100105
#ifdef __WINDOWS__

0 commit comments

Comments
 (0)