netconf.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. /*
  28. * This is the netconf service. It's currently used only by netconf nodes that
  29. * are run by ZeroTier itself. There is nothing to prevent you from running
  30. * your own if you wanted to create your own networks outside our system.
  31. *
  32. * That being said, we'd like to charge for private networks to support
  33. * ZeroTier One and future development efforts. So while this software is
  34. * open source and we're not going to stop you from sidestepping this, we
  35. * do ask -- honor system here -- that you pay for private networks if you
  36. * are going to use them for any commercial purpose such as a business VPN
  37. * alternative.
  38. *
  39. * This will at the moment only build on Linux and requires the mysql++
  40. * library, which is available here:
  41. *
  42. * http://tangentsoft.net/mysql++/
  43. *
  44. * (Packages are available for CentOS via EPEL and for any Debian distro.)
  45. *
  46. * This program must be built and installed in the services.d subfolder of
  47. * the ZeroTier One home folder of the node designated to act as a master
  48. * for networks. Doing so will enable the NETWORK_CONFIG_REQUEST protocol
  49. * verb.
  50. */
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <string.h>
  54. #include <stdint.h>
  55. #include <unistd.h>
  56. #include <errno.h>
  57. #include <sys/stat.h>
  58. #include <sys/types.h>
  59. #include <arpa/inet.h>
  60. #include <iostream>
  61. #include <string>
  62. #include <map>
  63. #include <list>
  64. #include <vector>
  65. #include <algorithm>
  66. #include <mysql++/mysql++.h>
  67. #include "../node/Constants.hpp"
  68. #include "../node/Dictionary.hpp"
  69. #include "../node/Identity.hpp"
  70. #include "../node/Utils.hpp"
  71. #include "../node/Mutex.hpp"
  72. #include "../node/NetworkConfig.hpp"
  73. #include "../node/CertificateOfMembership.hpp"
  74. using namespace ZeroTier;
  75. using namespace mysqlpp;
  76. static Mutex stdoutWriteLock;
  77. static Connection *dbCon = (Connection *)0;
  78. static char mysqlHost[64],mysqlPort[64],mysqlDatabase[64],mysqlUser[64],mysqlPassword[64];
  79. int main(int argc,char **argv)
  80. {
  81. {
  82. char *ee = getenv("ZT_NETCONF_MYSQL_HOST");
  83. if (!ee) {
  84. fprintf(stderr,"missing environment variable: ZT_NETCONF_MYSQL_HOST\n");
  85. return -1;
  86. }
  87. strcpy(mysqlHost,ee);
  88. ee = getenv("ZT_NETCONF_MYSQL_PORT");
  89. if (!ee)
  90. strcpy(mysqlPort,"3306");
  91. else strcpy(mysqlPort,ee);
  92. ee = getenv("ZT_NETCONF_MYSQL_DATABASE");
  93. if (!ee) {
  94. fprintf(stderr,"missing environment variable: ZT_NETCONF_MYSQL_DATABASE\n");
  95. return -1;
  96. }
  97. strcpy(mysqlDatabase,ee);
  98. ee = getenv("ZT_NETCONF_MYSQL_USER");
  99. if (!ee) {
  100. fprintf(stderr,"missing environment variable: ZT_NETCONF_MYSQL_USER\n");
  101. return -1;
  102. }
  103. strcpy(mysqlUser,ee);
  104. ee = getenv("ZT_NETCONF_MYSQL_PASSWORD");
  105. if (!ee) {
  106. fprintf(stderr,"missing environment variable: ZT_NETCONF_MYSQL_PASSWORD\n");
  107. return -1;
  108. }
  109. strcpy(mysqlPassword,ee);
  110. }
  111. char buf[131072],buf2[131072];
  112. Identity signingIdentity;
  113. std::string dictBuf;
  114. try {
  115. dbCon = new Connection(mysqlDatabase,mysqlHost,mysqlUser,mysqlPassword,(unsigned int)strtol(mysqlPort,(char **)0,10));
  116. if (dbCon->connected()) {
  117. fprintf(stderr,"connected to mysql server successfully\n");
  118. } else {
  119. fprintf(stderr,"unable to connect to database server\n");
  120. return -1;
  121. }
  122. } catch (std::exception &exc) {
  123. fprintf(stderr,"unable to connect to database server: %s\n",exc.what());
  124. return -1;
  125. }
  126. // Send ready message to tell parent that the service is up, and to
  127. // solicit netconf-init.
  128. {
  129. Dictionary response;
  130. response["type"] = "ready";
  131. std::string respm = response.toString();
  132. uint32_t respml = (uint32_t)htonl((uint32_t)respm.length());
  133. stdoutWriteLock.lock();
  134. write(STDOUT_FILENO,&respml,4);
  135. write(STDOUT_FILENO,respm.data(),respm.length());
  136. stdoutWriteLock.unlock();
  137. }
  138. for(;;) {
  139. for(int l=0;l<4;) {
  140. int n = (int)read(STDIN_FILENO,buf + l,4 - l);
  141. if (n < 0) {
  142. fprintf(stderr,"error reading frame size from stdin: %s\n",strerror(errno));
  143. return -1;
  144. }
  145. l += n;
  146. }
  147. unsigned int fsize = (unsigned int)ntohl(*((const uint32_t *)buf));
  148. while (dictBuf.length() < fsize) {
  149. int n = (int)read(STDIN_FILENO,buf,std::min((int)sizeof(buf),(int)(fsize - dictBuf.length())));
  150. if (n < 0) {
  151. fprintf(stderr,"error reading frame from stdin: %s\n",strerror(errno));
  152. return -1;
  153. }
  154. for(int i=0;i<n;++i)
  155. dictBuf.push_back(buf[i]);
  156. }
  157. Dictionary request(dictBuf);
  158. dictBuf = "";
  159. if (!dbCon->connected()) {
  160. fprintf(stderr,"connection to database server lost\n");
  161. return -1;
  162. }
  163. // Check QNetworkConfigRefresh (MEMORY table) and push network
  164. // config refreshes to queued peer/network pairs.
  165. try {
  166. Dictionary to;
  167. {
  168. Query q = dbCon->query();
  169. q << "SELECT DISTINCT LOWER(HEX(Node_id)) AS Node_id,LOWER(HEX(Network_id)) AS Network_id FROM QNetworkConfigRefresh";
  170. StoreQueryResult rs = q.store();
  171. for(unsigned long i=0;i<rs.num_rows();++i) {
  172. std::string &nwids = to[rs[i]["Node_id"].c_str()];
  173. if (nwids.length())
  174. nwids.push_back(',');
  175. nwids.append(rs[i]["Network_id"]);
  176. }
  177. }
  178. {
  179. Query q = dbCon->query();
  180. q << "DELETE FROM QNetworkConfigRefresh";
  181. q.exec();
  182. }
  183. Dictionary response;
  184. response["type"] = "netconf-push";
  185. response["to"] = to.toString();
  186. std::string respm = response.toString();
  187. uint32_t respml = (uint32_t)htonl((uint32_t)respm.length());
  188. stdoutWriteLock.lock();
  189. write(STDOUT_FILENO,&respml,4);
  190. write(STDOUT_FILENO,respm.data(),respm.length());
  191. stdoutWriteLock.unlock();
  192. } catch ( ... ) {}
  193. try {
  194. const std::string &reqType = request.get("type");
  195. if (reqType == "netconf-init") { // initialization to set things like netconf's identity
  196. Identity netconfId(request.get("netconfId"));
  197. if ((netconfId)&&(netconfId.hasPrivate())) {
  198. signingIdentity = netconfId;
  199. fprintf(stderr,"got netconf signing identity: %s\n",signingIdentity.toString(false).c_str());
  200. } else {
  201. fprintf(stderr,"netconfId invalid or lacks private key\n");
  202. return -1;
  203. }
  204. } else if (reqType == "netconf-request") { // NETWORK_CONFIG_REQUEST packet
  205. if (!signingIdentity) {
  206. fprintf(stderr,"no signing identity; missing netconf-init?\n");
  207. return -1;
  208. }
  209. // Deserialize querying peer identity and network ID
  210. Identity peerIdentity(request.get("peerId"));
  211. uint64_t nwid = strtoull(request.get("nwid").c_str(),(char **)0,16);
  212. std::string fromAddr(request.get("from",""));
  213. // Meta-information from node, such as (future) geo-location stuff
  214. Dictionary meta;
  215. if (request.contains("meta"))
  216. meta.fromString(request.get("meta"));
  217. // Check validity of node's identity, ignore request on failure
  218. if (!peerIdentity.locallyValidate()) {
  219. fprintf(stderr,"identity failed validity check: %s\n",peerIdentity.toString(false).c_str());
  220. continue;
  221. }
  222. // Save node's identity if unknown
  223. {
  224. Query q = dbCon->query();
  225. q << "SELECT identity FROM Node WHERE id = " << peerIdentity.address().toInt();
  226. StoreQueryResult rs = q.store();
  227. if (rs.num_rows() > 0) {
  228. if (rs[0]["identity"] != peerIdentity.toString(false)) {
  229. // TODO: handle collisions...
  230. continue;
  231. }
  232. } else {
  233. q = dbCon->query();
  234. q << "INSERT INTO Node (id,creationTime,identity) VALUES (" << peerIdentity.address().toInt() << "," << Utils::now() << "," << quote << peerIdentity.toString(false) << ")";
  235. if (!q.exec()) {
  236. fprintf(stderr,"error inserting Node row for peer %s, aborting netconf request\n",peerIdentity.address().toString().c_str());
  237. continue;
  238. }
  239. // TODO: launch background validation
  240. }
  241. }
  242. // Look up core network information
  243. bool isOpen = false;
  244. unsigned int multicastPrefixBits = 0;
  245. unsigned int multicastDepth = 0;
  246. bool emulateArp = false;
  247. bool emulateNdp = false;
  248. unsigned int arpCacheTtl = 0;
  249. unsigned int ndpCacheTtl = 0;
  250. std::string name;
  251. std::string desc;
  252. {
  253. Query q = dbCon->query();
  254. q << "SELECT name,`desc`,isOpen,multicastPrefixBits,multicastDepth,emulateArp,emulateNdp,arpCacheTtl,ndpCacheTtl FROM Network WHERE id = " << nwid;
  255. StoreQueryResult rs = q.store();
  256. if (rs.num_rows() > 0) {
  257. name = rs[0]["name"].c_str();
  258. desc = rs[0]["desc"].c_str();
  259. isOpen = ((int)rs[0]["isOpen"] > 0);
  260. emulateArp = ((int)rs[0]["emulateArp"] > 0);
  261. emulateNdp = ((int)rs[0]["emulateNdp"] > 0);
  262. arpCacheTtl = (unsigned int)rs[0]["arpCacheTtl"];
  263. ndpCacheTtl = (unsigned int)rs[0]["ndpCacheTtl"];
  264. multicastPrefixBits = (unsigned int)rs[0]["multicastPrefixBits"];
  265. multicastDepth = (unsigned int)rs[0]["multicastDepth"];
  266. } else {
  267. Dictionary response;
  268. response["peer"] = peerIdentity.address().toString();
  269. response["nwid"] = request.get("nwid");
  270. response["type"] = "netconf-response";
  271. response["requestId"] = request.get("requestId");
  272. response["error"] = "OBJ_NOT_FOUND";
  273. std::string respm = response.toString();
  274. uint32_t respml = (uint32_t)htonl((uint32_t)respm.length());
  275. stdoutWriteLock.lock();
  276. write(STDOUT_FILENO,&respml,4);
  277. write(STDOUT_FILENO,respm.data(),respm.length());
  278. stdoutWriteLock.unlock();
  279. continue; // ABORT, wait for next request
  280. }
  281. }
  282. // Check membership if this is a closed network
  283. bool authenticated = true;
  284. if (!isOpen) {
  285. Query q = dbCon->query();
  286. q << "SELECT Node_id FROM NetworkNodes WHERE Network_id = " << nwid << " AND Node_id = " << peerIdentity.address().toInt();
  287. StoreQueryResult rs = q.store();
  288. if (!rs.num_rows()) {
  289. Dictionary response;
  290. response["peer"] = peerIdentity.address().toString();
  291. response["nwid"] = request.get("nwid");
  292. response["type"] = "netconf-response";
  293. response["requestId"] = request.get("requestId");
  294. response["error"] = "ACCESS_DENIED";
  295. std::string respm = response.toString();
  296. uint32_t respml = (uint32_t)htonl((uint32_t)respm.length());
  297. stdoutWriteLock.lock();
  298. write(STDOUT_FILENO,&respml,4);
  299. write(STDOUT_FILENO,respm.data(),respm.length());
  300. stdoutWriteLock.unlock();
  301. authenticated = false;
  302. }
  303. }
  304. // Update most recent activity entry for this peer, also indicating
  305. // whether authentication was successful.
  306. {
  307. if (fromAddr.length()) {
  308. Query q = dbCon->query();
  309. q << "INSERT INTO NetworkActivity (Network_id,Node_id,lastActivityTime,authenticated,lastActivityFrom) VALUES (" << nwid << "," << peerIdentity.address().toInt() << "," << Utils::now() << "," << (authenticated ? 1 : 0) << "," << quote << fromAddr << ") ON DUPLICATE KEY UPDATE lastActivityTime = VALUES(lastActivityTime),authenticated = VALUES(authenticated),lastActivityFrom = VALUES(lastActivityFrom)";
  310. q.exec();
  311. } else {
  312. Query q = dbCon->query();
  313. q << "INSERT INTO NetworkActivity (Network_id,Node_id,lastActivityTime,authenticated) VALUES (" << nwid << "," << peerIdentity.address().toInt() << "," << Utils::now() << "," << (authenticated ? 1 : 0) << ") ON DUPLICATE KEY UPDATE lastActivityTime = VALUES(lastActivityTime),authenticated = VALUES(authenticated)";
  314. q.exec();
  315. }
  316. }
  317. if (!authenticated)
  318. continue; // ABORT, wait for next request
  319. // Get list of etherTypes in comma-delimited hex format
  320. std::string etherTypeWhitelist;
  321. {
  322. Query q = dbCon->query();
  323. q << "SELECT DISTINCT LOWER(HEX(etherType)) AS etherType FROM NetworkEthertypes WHERE Network_id = " << nwid;
  324. StoreQueryResult rs = q.store();
  325. for(unsigned long i=0;i<rs.num_rows();++i) {
  326. if (etherTypeWhitelist.length() > 0)
  327. etherTypeWhitelist.push_back(',');
  328. etherTypeWhitelist.append(rs[i]["etherType"].c_str());
  329. }
  330. }
  331. // Get multicast group rates in dictionary format
  332. Dictionary multicastRates;
  333. {
  334. Query q = dbCon->query();
  335. q << "SELECT DISTINCT multicastGroupMac,multicastGroupAdi,preload,maxBalance,accrual FROM NetworkMulticastRates WHERE Network_id = " << nwid;
  336. StoreQueryResult rs = q.store();
  337. for(unsigned long i=0;i<rs.num_rows();++i) {
  338. unsigned long preload = (unsigned long)rs[i]["preload"];
  339. unsigned long maxBalance = (unsigned long)rs[i]["maxBalance"];
  340. unsigned long accrual = (unsigned long)rs[i]["accrual"];
  341. unsigned long long mac = (unsigned long long)rs[i]["multicastGroupMac"];
  342. sprintf(buf,"%.12llx/%lx",(mac & 0xffffffffffffULL),(unsigned long)rs[i]["multicastGroupAdi"]);
  343. sprintf(buf2,"%lx,%lx,%lx",preload,maxBalance,accrual);
  344. multicastRates[buf] = buf2;
  345. }
  346. }
  347. // Check for (or assign?) static IP address assignments
  348. std::string ipv4Static;
  349. std::string ipv6Static;
  350. {
  351. Query q = dbCon->query();
  352. q << "SELECT INET_NTOA(ip) AS ip,netmaskBits FROM IPv4Static WHERE Node_id = " << peerIdentity.address().toInt() << " AND Network_id = " << nwid;
  353. StoreQueryResult rs = q.store();
  354. if (rs.num_rows() > 0) {
  355. for(int i=0;i<rs.num_rows();++i) {
  356. if (ipv4Static.length())
  357. ipv4Static.push_back(',');
  358. ipv4Static.append(rs[i]["ip"].c_str());
  359. ipv4Static.push_back('/');
  360. ipv4Static.append(rs[i]["netmaskBits"].c_str());
  361. }
  362. }
  363. // Try to auto-assign if there's any auto-assign networks with space
  364. // available.
  365. if (!ipv4Static.length()) {
  366. unsigned char addressBytes[5];
  367. peerIdentity.address().copyTo(addressBytes,5);
  368. q = dbCon->query();
  369. q << "SELECT ipNet,netmaskBits FROM IPv4AutoAssign WHERE Network_id = " << nwid;
  370. rs = q.store();
  371. if (rs.num_rows() > 0) {
  372. for(int aaRow=0;aaRow<rs.num_rows();++aaRow) {
  373. uint32_t ipNet = (uint32_t)((unsigned long)rs[aaRow]["ipNet"]);
  374. unsigned int netmaskBits = (unsigned int)rs[aaRow]["netmaskBits"];
  375. uint32_t tryIp = (((uint32_t)addressBytes[1]) << 24) |
  376. (((uint32_t)addressBytes[2]) << 16) |
  377. (((uint32_t)addressBytes[3]) << 8) |
  378. ((((uint32_t)addressBytes[4]) % 254) + 1);
  379. tryIp &= (0xffffffff >> netmaskBits);
  380. tryIp |= ipNet;
  381. for(int k=0;k<100000;++k) {
  382. Query q2 = dbCon->query();
  383. q2 << "INSERT INTO IPv4Static (Network_id,Node_id,ip,netmaskBits) VALUES (" << nwid << "," << peerIdentity.address().toInt() << "," << tryIp << "," << netmaskBits << ")";
  384. if (q2.exec()) {
  385. sprintf(buf,"%u.%u.%u.%u",(unsigned int)((tryIp >> 24) & 0xff),(unsigned int)((tryIp >> 16) & 0xff),(unsigned int)((tryIp >> 8) & 0xff),(unsigned int)(tryIp & 0xff));
  386. if (ipv4Static.length())
  387. ipv4Static.push_back(',');
  388. ipv4Static.append(buf);
  389. ipv4Static.push_back('/');
  390. sprintf(buf,"%u",netmaskBits);
  391. ipv4Static.append(buf);
  392. break;
  393. } else { // insert will fail if IP is in use due to uniqueness constraints in DB
  394. ++tryIp;
  395. if ((tryIp & 0xff) == 0)
  396. tryIp |= 1;
  397. tryIp &= (0xffffffff >> netmaskBits);
  398. tryIp |= ipNet;
  399. }
  400. }
  401. if (ipv4Static.length())
  402. break;
  403. }
  404. }
  405. }
  406. }
  407. // Assemble response dictionary to send to peer
  408. Dictionary netconf;
  409. sprintf(buf,"%.16llx",(unsigned long long)nwid);
  410. netconf[ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID] = buf;
  411. netconf[ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO] = peerIdentity.address().toString();
  412. netconf[ZT_NETWORKCONFIG_DICT_KEY_NAME] = name;
  413. netconf[ZT_NETWORKCONFIG_DICT_KEY_DESC] = desc;
  414. netconf[ZT_NETWORKCONFIG_DICT_KEY_IS_OPEN] = (isOpen ? "1" : "0");
  415. netconf[ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES] = etherTypeWhitelist;
  416. netconf[ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_RATES] = multicastRates.toString();
  417. sprintf(buf,"%llx",(unsigned long long)Utils::now());
  418. netconf[ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP] = buf;
  419. netconf[ZT_NETWORKCONFIG_DICT_KEY_EMULATE_ARP] = (emulateArp ? "1" : "0");
  420. netconf[ZT_NETWORKCONFIG_DICT_KEY_EMULATE_NDP] = (emulateNdp ? "1" : "0");
  421. if (arpCacheTtl) {
  422. sprintf(buf,"%x",arpCacheTtl);
  423. netconf[ZT_NETWORKCONFIG_DICT_KEY_ARP_CACHE_TTL] = buf;
  424. }
  425. if (ndpCacheTtl) {
  426. sprintf(buf,"%x",ndpCacheTtl);
  427. netconf[ZT_NETWORKCONFIG_DICT_KEY_NDP_CACHE_TTL] = buf;
  428. }
  429. if (multicastPrefixBits) {
  430. sprintf(buf,"%x",multicastPrefixBits);
  431. netconf[ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_PREFIX_BITS] = buf;
  432. }
  433. if (multicastDepth) {
  434. sprintf(buf,"%x",multicastDepth);
  435. netconf[ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_DEPTH] = buf;
  436. }
  437. if (ipv4Static.length())
  438. netconf[ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC] = ipv4Static;
  439. if (ipv6Static.length())
  440. netconf[ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC] = ipv6Static;
  441. if ((!isOpen)&&(authenticated)) {
  442. CertificateOfMembership com(Utils::now(),ZT_NETWORK_AUTOCONF_DELAY * 3,nwid,peerIdentity.address());
  443. com.sign(signingIdentity);
  444. netconf[ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP] = com.toString();
  445. }
  446. // Send netconf as service bus response
  447. {
  448. Dictionary response;
  449. response["peer"] = peerIdentity.address().toString();
  450. response["nwid"] = request.get("nwid");
  451. response["type"] = "netconf-response";
  452. response["requestId"] = request.get("requestId");
  453. response["netconf"] = netconf.toString();
  454. std::string respm = response.toString();
  455. uint32_t respml = (uint32_t)htonl((uint32_t)respm.length());
  456. stdoutWriteLock.lock();
  457. write(STDOUT_FILENO,&respml,4);
  458. write(STDOUT_FILENO,respm.data(),respm.length());
  459. stdoutWriteLock.unlock();
  460. // LOOP, wait for next request
  461. }
  462. }
  463. } catch (std::exception &exc) {
  464. fprintf(stderr,"unexpected exception handling message: %s\n",exc.what());
  465. } catch ( ... ) {
  466. fprintf(stderr,"unexpected exception handling message: unknown exception\n");
  467. }
  468. }
  469. }