protocol_auth.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*
  2. protocol_auth.c -- handle the meta-protocol, authentication
  3. Copyright (C) 1999-2005 Ivo Timmermans,
  4. 2000-2016 Guus Sliepen <guus@tinc-vpn.org>
  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 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include "system.h"
  18. #include <openssl/sha.h>
  19. #include <openssl/rand.h>
  20. #include <openssl/err.h>
  21. #include <openssl/evp.h>
  22. #include "avl_tree.h"
  23. #include "conf.h"
  24. #include "connection.h"
  25. #include "edge.h"
  26. #include "graph.h"
  27. #include "logger.h"
  28. #include "meta.h"
  29. #include "net.h"
  30. #include "netutl.h"
  31. #include "node.h"
  32. #include "protocol.h"
  33. #include "proxy.h"
  34. #include "utils.h"
  35. #include "xalloc.h"
  36. bool send_id(connection_t *c) {
  37. if(proxytype && c->outgoing && !c->status.proxy_passed) {
  38. return send_proxyrequest(c);
  39. }
  40. return send_request(c, "%d %s %d", ID, myself->connection->name,
  41. myself->connection->protocol_version);
  42. }
  43. bool id_h(connection_t *c) {
  44. char name[MAX_STRING_SIZE];
  45. if(sscanf(c->buffer, "%*d " MAX_STRING " %d", name, &c->protocol_version) != 2) {
  46. logger(LOG_ERR, "Got bad %s from %s (%s)", "ID", c->name,
  47. c->hostname);
  48. return false;
  49. }
  50. /* Check if identity is a valid name */
  51. if(!check_id(name) || !strcmp(name, myself->name)) {
  52. logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ID", c->name,
  53. c->hostname, "invalid name");
  54. return false;
  55. }
  56. /* If this is an outgoing connection, make sure we are connected to the right host */
  57. if(c->outgoing) {
  58. if(strcmp(c->name, name)) {
  59. logger(LOG_ERR, "Peer %s is %s instead of %s", c->hostname, name,
  60. c->name);
  61. return false;
  62. }
  63. } else {
  64. if(c->name) {
  65. free(c->name);
  66. }
  67. c->name = xstrdup(name);
  68. }
  69. /* Check if version matches */
  70. if(c->protocol_version != myself->connection->protocol_version) {
  71. logger(LOG_ERR, "Peer %s (%s) uses incompatible version %d",
  72. c->name, c->hostname, c->protocol_version);
  73. return false;
  74. }
  75. if(bypass_security) {
  76. if(!c->config_tree) {
  77. init_configuration(&c->config_tree);
  78. }
  79. c->allow_request = ACK;
  80. if(!c->outgoing) {
  81. send_id(c);
  82. }
  83. return send_ack(c);
  84. }
  85. if(!c->config_tree) {
  86. init_configuration(&c->config_tree);
  87. if(!read_connection_config(c)) {
  88. logger(LOG_ERR, "Peer %s had unknown identity (%s)", c->hostname,
  89. c->name);
  90. return false;
  91. }
  92. }
  93. if(!read_rsa_public_key(c)) {
  94. return false;
  95. }
  96. c->allow_request = METAKEY;
  97. if(!c->outgoing) {
  98. send_id(c);
  99. }
  100. return send_metakey(c);
  101. }
  102. static uint64_t byte_budget(const EVP_CIPHER *cipher) {
  103. /* Hopefully some failsafe way to calculate the maximum amount of bytes to
  104. send/receive with a given cipher before we might run into birthday paradox
  105. attacks. Because we might use different modes, the block size of the mode
  106. might be 1 byte. In that case, use the IV length. Ensure the whole thing
  107. is limited to what can be represented with a 64 bits integer.
  108. */
  109. int ivlen = EVP_CIPHER_iv_length(cipher);
  110. int blklen = EVP_CIPHER_block_size(cipher);
  111. int len = blklen > 1 ? blklen : ivlen > 1 ? ivlen : 8;
  112. int bits = len * 4 - 1;
  113. return bits < 64 ? UINT64_C(1) << bits : UINT64_MAX;
  114. }
  115. bool send_metakey(connection_t *c) {
  116. bool x;
  117. int len = RSA_size(c->rsa_key);
  118. /* Allocate buffers for the meta key */
  119. char buffer[2 * len + 1];
  120. c->outkey = xrealloc(c->outkey, len);
  121. if(!c->outctx) {
  122. c->outctx = EVP_CIPHER_CTX_new();
  123. if(!c->outctx) {
  124. abort();
  125. }
  126. }
  127. /* Copy random data to the buffer */
  128. if(1 != RAND_bytes((unsigned char *)c->outkey, len)) {
  129. int err = ERR_get_error();
  130. logger(LOG_ERR, "Failed to generate meta key (%s)", ERR_error_string(err, NULL));
  131. return false;
  132. }
  133. /* The message we send must be smaller than the modulus of the RSA key.
  134. By definition, for a key of k bits, the following formula holds:
  135. 2^(k-1) <= modulus < 2^(k)
  136. Where ^ means "to the power of", not "xor".
  137. This means that to be sure, we must choose our message < 2^(k-1).
  138. This can be done by setting the most significant bit to zero.
  139. */
  140. c->outkey[0] &= 0x7F;
  141. ifdebug(SCARY_THINGS) {
  142. bin2hex(c->outkey, buffer, len);
  143. buffer[len * 2] = '\0';
  144. logger(LOG_DEBUG, "Generated random meta key (unencrypted): %s",
  145. buffer);
  146. }
  147. /* Encrypt the random data
  148. We do not use one of the PKCS padding schemes here.
  149. This is allowed, because we encrypt a totally random string
  150. with a length equal to that of the modulus of the RSA key.
  151. */
  152. if(RSA_public_encrypt(len, (unsigned char *)c->outkey, (unsigned char *)buffer, c->rsa_key, RSA_NO_PADDING) != len) {
  153. logger(LOG_ERR, "Error during encryption of meta key for %s (%s): %s",
  154. c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
  155. return false;
  156. }
  157. /* Convert the encrypted random data to a hexadecimal formatted string */
  158. bin2hex(buffer, buffer, len);
  159. buffer[len * 2] = '\0';
  160. /* Send the meta key */
  161. x = send_request(c, "%d %d %d %d %d %s", METAKEY,
  162. c->outcipher ? EVP_CIPHER_nid(c->outcipher) : 0,
  163. c->outdigest ? EVP_MD_type(c->outdigest) : 0, c->outmaclength,
  164. c->outcompression, buffer);
  165. /* Further outgoing requests are encrypted with the key we just generated */
  166. if(c->outcipher) {
  167. if(!EVP_EncryptInit(c->outctx, c->outcipher,
  168. (unsigned char *)c->outkey + len - EVP_CIPHER_key_length(c->outcipher),
  169. (unsigned char *)c->outkey + len - EVP_CIPHER_key_length(c->outcipher) -
  170. EVP_CIPHER_iv_length(c->outcipher))) {
  171. logger(LOG_ERR, "Error during initialisation of cipher for %s (%s): %s",
  172. c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
  173. return false;
  174. }
  175. c->outbudget = byte_budget(c->outcipher);
  176. c->status.encryptout = true;
  177. }
  178. return x;
  179. }
  180. bool metakey_h(connection_t *c) {
  181. char buffer[MAX_STRING_SIZE];
  182. int cipher, digest, maclength, compression;
  183. int len;
  184. if(sscanf(c->buffer, "%*d %d %d %d %d " MAX_STRING, &cipher, &digest, &maclength, &compression, buffer) != 5) {
  185. logger(LOG_ERR, "Got bad %s from %s (%s)", "METAKEY", c->name,
  186. c->hostname);
  187. return false;
  188. }
  189. len = RSA_size(myself->connection->rsa_key);
  190. /* Check if the length of the meta key is all right */
  191. if(strlen(buffer) != (size_t)len * 2) {
  192. logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong keylength");
  193. return false;
  194. }
  195. /* Allocate buffers for the meta key */
  196. c->inkey = xrealloc(c->inkey, len);
  197. if(!c->inctx) {
  198. c->inctx = EVP_CIPHER_CTX_new();
  199. if(!c->inctx) {
  200. abort();
  201. }
  202. }
  203. /* Convert the challenge from hexadecimal back to binary */
  204. if(!hex2bin(buffer, buffer, len)) {
  205. logger(LOG_ERR, "Got bad %s from %s(%s): %s", "METAKEY", c->name, c->hostname, "invalid key");
  206. return false;
  207. }
  208. /* Decrypt the meta key */
  209. if(RSA_private_decrypt(len, (unsigned char *)buffer, (unsigned char *)c->inkey, myself->connection->rsa_key, RSA_NO_PADDING) != len) { /* See challenge() */
  210. logger(LOG_ERR, "Error during decryption of meta key for %s (%s): %s",
  211. c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
  212. return false;
  213. }
  214. ifdebug(SCARY_THINGS) {
  215. bin2hex(c->inkey, buffer, len);
  216. buffer[len * 2] = '\0';
  217. logger(LOG_DEBUG, "Received random meta key (unencrypted): %s", buffer);
  218. }
  219. /* All incoming requests will now be encrypted. */
  220. /* Check and lookup cipher and digest algorithms */
  221. if(cipher) {
  222. c->incipher = EVP_get_cipherbynid(cipher);
  223. if(!c->incipher) {
  224. logger(LOG_ERR, "%s (%s) uses unknown cipher!", c->name, c->hostname);
  225. return false;
  226. }
  227. if(!EVP_DecryptInit(c->inctx, c->incipher,
  228. (unsigned char *)c->inkey + len - EVP_CIPHER_key_length(c->incipher),
  229. (unsigned char *)c->inkey + len - EVP_CIPHER_key_length(c->incipher) -
  230. EVP_CIPHER_iv_length(c->incipher))) {
  231. logger(LOG_ERR, "Error during initialisation of cipher from %s (%s): %s",
  232. c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
  233. return false;
  234. }
  235. c->inbudget = byte_budget(c->incipher);
  236. c->status.decryptin = true;
  237. } else {
  238. logger(LOG_ERR, "%s (%s) uses null cipher!", c->name, c->hostname);
  239. return false;
  240. }
  241. c->inmaclength = maclength;
  242. if(digest) {
  243. c->indigest = EVP_get_digestbynid(digest);
  244. if(!c->indigest) {
  245. logger(LOG_ERR, "Node %s (%s) uses unknown digest!", c->name, c->hostname);
  246. return false;
  247. }
  248. if(c->inmaclength > EVP_MD_size(c->indigest) || c->inmaclength < 0) {
  249. logger(LOG_ERR, "%s (%s) uses bogus MAC length!", c->name, c->hostname);
  250. return false;
  251. }
  252. } else {
  253. logger(LOG_ERR, "%s (%s) uses null digest!", c->name, c->hostname);
  254. return false;
  255. }
  256. c->incompression = compression;
  257. c->allow_request = CHALLENGE;
  258. return send_challenge(c);
  259. }
  260. bool send_challenge(connection_t *c) {
  261. /* CHECKME: what is most reasonable value for len? */
  262. int len = RSA_size(c->rsa_key);
  263. /* Allocate buffers for the challenge */
  264. char buffer[2 * len + 1];
  265. c->hischallenge = xrealloc(c->hischallenge, len);
  266. /* Copy random data to the buffer */
  267. if(1 != RAND_bytes((unsigned char *)c->hischallenge, len)) {
  268. int err = ERR_get_error();
  269. logger(LOG_ERR, "Failed to generate challenge (%s)", ERR_error_string(err, NULL));
  270. return false; // Do not send predictable challenges, let connection attempt fail.
  271. }
  272. /* Convert to hex */
  273. bin2hex(c->hischallenge, buffer, len);
  274. buffer[len * 2] = '\0';
  275. /* Send the challenge */
  276. return send_request(c, "%d %s", CHALLENGE, buffer);
  277. }
  278. bool challenge_h(connection_t *c) {
  279. char buffer[MAX_STRING_SIZE];
  280. int len;
  281. if(sscanf(c->buffer, "%*d " MAX_STRING, buffer) != 1) {
  282. logger(LOG_ERR, "Got bad %s from %s (%s)", "CHALLENGE", c->name,
  283. c->hostname);
  284. return false;
  285. }
  286. len = RSA_size(myself->connection->rsa_key);
  287. /* Check if the length of the challenge is all right */
  288. if(strlen(buffer) != (size_t)len * 2) {
  289. logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name,
  290. c->hostname, "wrong challenge length");
  291. return false;
  292. }
  293. /* Allocate buffers for the challenge */
  294. c->mychallenge = xrealloc(c->mychallenge, len);
  295. /* Convert the challenge from hexadecimal back to binary */
  296. if(!hex2bin(buffer, c->mychallenge, len)) {
  297. logger(LOG_ERR, "Got bad %s from %s(%s): %s", "CHALLENGE", c->name, c->hostname, "invalid challenge");
  298. return false;
  299. }
  300. c->allow_request = CHAL_REPLY;
  301. /* Rest is done by send_chal_reply() */
  302. if(c->outgoing) {
  303. return send_chal_reply(c);
  304. } else {
  305. return true;
  306. }
  307. }
  308. bool send_chal_reply(connection_t *c) {
  309. char hash[EVP_MAX_MD_SIZE * 2 + 1];
  310. EVP_MD_CTX *ctx;
  311. /* Calculate the hash from the challenge we received */
  312. ctx = EVP_MD_CTX_create();
  313. if(!ctx) {
  314. abort();
  315. }
  316. if(!EVP_DigestInit(ctx, c->indigest)
  317. || !EVP_DigestUpdate(ctx, c->mychallenge, RSA_size(myself->connection->rsa_key))
  318. || !EVP_DigestFinal(ctx, (unsigned char *)hash, NULL)) {
  319. EVP_MD_CTX_destroy(ctx);
  320. logger(LOG_ERR, "Error during calculation of response for %s (%s): %s",
  321. c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
  322. return false;
  323. }
  324. EVP_MD_CTX_destroy(ctx);
  325. /* Convert the hash to a hexadecimal formatted string */
  326. bin2hex(hash, hash, EVP_MD_size(c->indigest));
  327. hash[EVP_MD_size(c->indigest) * 2] = '\0';
  328. /* Send the reply */
  329. return send_request(c, "%d %s", CHAL_REPLY, hash);
  330. }
  331. bool chal_reply_h(connection_t *c) {
  332. char hishash[MAX_STRING_SIZE];
  333. char myhash[EVP_MAX_MD_SIZE];
  334. EVP_MD_CTX *ctx;
  335. if(sscanf(c->buffer, "%*d " MAX_STRING, hishash) != 1) {
  336. logger(LOG_ERR, "Got bad %s from %s (%s)", "CHAL_REPLY", c->name,
  337. c->hostname);
  338. return false;
  339. }
  340. /* Check if the length of the hash is all right */
  341. if(strlen(hishash) != (size_t)EVP_MD_size(c->outdigest) * 2) {
  342. logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name,
  343. c->hostname, "wrong challenge reply length");
  344. return false;
  345. }
  346. /* Convert the hash to binary format */
  347. if(!hex2bin(hishash, hishash, EVP_MD_size(c->outdigest))) {
  348. logger(LOG_ERR, "Got bad %s from %s(%s): %s", "CHAL_REPLY", c->name, c->hostname, "invalid hash");
  349. return false;
  350. }
  351. /* Calculate the hash from the challenge we sent */
  352. ctx = EVP_MD_CTX_create();
  353. if(!ctx) {
  354. abort();
  355. }
  356. if(!EVP_DigestInit(ctx, c->outdigest)
  357. || !EVP_DigestUpdate(ctx, c->hischallenge, RSA_size(c->rsa_key))
  358. || !EVP_DigestFinal(ctx, (unsigned char *)myhash, NULL)) {
  359. EVP_MD_CTX_destroy(ctx);
  360. logger(LOG_ERR, "Error during calculation of response from %s (%s): %s",
  361. c->name, c->hostname, ERR_error_string(ERR_get_error(), NULL));
  362. return false;
  363. }
  364. EVP_MD_CTX_destroy(ctx);
  365. /* Verify the incoming hash with the calculated hash */
  366. if(memcmp(hishash, myhash, EVP_MD_size(c->outdigest))) {
  367. logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name,
  368. c->hostname, "wrong challenge reply");
  369. ifdebug(SCARY_THINGS) {
  370. bin2hex(myhash, hishash, SHA_DIGEST_LENGTH);
  371. hishash[SHA_DIGEST_LENGTH * 2] = '\0';
  372. logger(LOG_DEBUG, "Expected challenge reply: %s", hishash);
  373. }
  374. return false;
  375. }
  376. /* Identity has now been positively verified.
  377. Send an acknowledgement with the rest of the information needed.
  378. */
  379. c->allow_request = ACK;
  380. if(!c->outgoing) {
  381. send_chal_reply(c);
  382. }
  383. return send_ack(c);
  384. }
  385. bool send_ack(connection_t *c) {
  386. /* ACK message contains rest of the information the other end needs
  387. to create node_t and edge_t structures. */
  388. struct timeval now;
  389. bool choice;
  390. /* Estimate weight */
  391. gettimeofday(&now, NULL);
  392. c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000;
  393. /* Check some options */
  394. if((get_config_bool(lookup_config(c->config_tree, "IndirectData"), &choice) && choice) || myself->options & OPTION_INDIRECT) {
  395. c->options |= OPTION_INDIRECT;
  396. }
  397. if((get_config_bool(lookup_config(c->config_tree, "TCPOnly"), &choice) && choice) || myself->options & OPTION_TCPONLY) {
  398. c->options |= OPTION_TCPONLY | OPTION_INDIRECT;
  399. }
  400. if(myself->options & OPTION_PMTU_DISCOVERY && !(c->options & OPTION_TCPONLY)) {
  401. c->options |= OPTION_PMTU_DISCOVERY;
  402. }
  403. choice = myself->options & OPTION_CLAMP_MSS;
  404. get_config_bool(lookup_config(c->config_tree, "ClampMSS"), &choice);
  405. if(choice) {
  406. c->options |= OPTION_CLAMP_MSS;
  407. }
  408. get_config_int(lookup_config(c->config_tree, "Weight"), &c->estimated_weight);
  409. return send_request(c, "%d %s %d %x", ACK, myport, c->estimated_weight, c->options);
  410. }
  411. static void send_everything(connection_t *c) {
  412. avl_node_t *node, *node2;
  413. node_t *n;
  414. subnet_t *s;
  415. edge_t *e;
  416. /* Send all known subnets and edges */
  417. if(tunnelserver) {
  418. for(node = myself->subnet_tree->head; node; node = node->next) {
  419. s = node->data;
  420. send_add_subnet(c, s);
  421. }
  422. return;
  423. }
  424. for(node = node_tree->head; node; node = node->next) {
  425. n = node->data;
  426. for(node2 = n->subnet_tree->head; node2; node2 = node2->next) {
  427. s = node2->data;
  428. send_add_subnet(c, s);
  429. }
  430. for(node2 = n->edge_tree->head; node2; node2 = node2->next) {
  431. e = node2->data;
  432. send_add_edge(c, e);
  433. }
  434. }
  435. }
  436. bool ack_h(connection_t *c) {
  437. char hisport[MAX_STRING_SIZE];
  438. int weight, mtu;
  439. uint32_t options;
  440. node_t *n;
  441. bool choice;
  442. if(sscanf(c->buffer, "%*d " MAX_STRING " %d %x", hisport, &weight, &options) != 3) {
  443. logger(LOG_ERR, "Got bad %s from %s (%s)", "ACK", c->name,
  444. c->hostname);
  445. return false;
  446. }
  447. /* Check if we already have a node_t for him */
  448. n = lookup_node(c->name);
  449. if(!n) {
  450. n = new_node();
  451. n->name = xstrdup(c->name);
  452. node_add(n);
  453. } else {
  454. if(n->connection) {
  455. /* Oh dear, we already have a connection to this node. */
  456. ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Established a second connection with %s (%s), closing old connection",
  457. n->name, n->hostname);
  458. terminate_connection(n->connection, false);
  459. /* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */
  460. graph();
  461. }
  462. }
  463. n->connection = c;
  464. c->node = n;
  465. if(!(c->options & options & OPTION_PMTU_DISCOVERY)) {
  466. c->options &= ~OPTION_PMTU_DISCOVERY;
  467. options &= ~OPTION_PMTU_DISCOVERY;
  468. }
  469. c->options |= options;
  470. if(get_config_int(lookup_config(c->config_tree, "PMTU"), &mtu) && mtu < n->mtu) {
  471. n->mtu = mtu;
  472. }
  473. if(get_config_int(lookup_config(config_tree, "PMTU"), &mtu) && mtu < n->mtu) {
  474. n->mtu = mtu;
  475. }
  476. if(get_config_bool(lookup_config(c->config_tree, "ClampMSS"), &choice)) {
  477. if(choice) {
  478. c->options |= OPTION_CLAMP_MSS;
  479. } else {
  480. c->options &= ~OPTION_CLAMP_MSS;
  481. }
  482. }
  483. /* Activate this connection */
  484. c->allow_request = ALL;
  485. c->status.active = true;
  486. ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection with %s (%s) activated", c->name,
  487. c->hostname);
  488. /* Send him everything we know */
  489. send_everything(c);
  490. /* Create an edge_t for this connection */
  491. c->edge = new_edge();
  492. c->edge->from = myself;
  493. c->edge->to = n;
  494. sockaddrcpy(&c->edge->address, &c->address);
  495. sockaddr_setport(&c->edge->address, hisport);
  496. c->edge->weight = (weight + c->estimated_weight) / 2;
  497. c->edge->connection = c;
  498. c->edge->options = c->options;
  499. edge_add(c->edge);
  500. /* Notify everyone of the new edge */
  501. if(tunnelserver) {
  502. send_add_edge(c, c->edge);
  503. } else {
  504. send_add_edge(everyone, c->edge);
  505. }
  506. /* Run MST and SSSP algorithms */
  507. graph();
  508. return true;
  509. }