+
+ /* Forward it if necessary */
+
+ if(to != myself) {
+ if(tunnelserver)
+ return false;
+
+ if(!to->status.reachable) {
+ logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
+ "ANS_KEY", c->name, c->hostname, to_name);
+ return true;
+ }
+
+ return send_request(to->nexthop->connection, "%s", c->buffer);
+ }
+
+ /* Update our copy of the origin's packet key */
+ from->outkey = xrealloc(from->outkey, strlen(key) / 2);
+
+ from->outkey = xstrdup(key);
+ from->outkeylength = strlen(key) / 2;
+ hex2bin(key, from->outkey, from->outkeylength);
+
+ from->status.waitingforkey = false;
+ /* Check and lookup cipher and digest algorithms */
+
+ if(cipher) {
+ from->outcipher = EVP_get_cipherbynid(cipher);
+
+ if(!from->outcipher) {
+ logger(LOG_ERR, "Node %s (%s) uses unknown cipher!", from->name,
+ from->hostname);
+ return false;
+ }
+
+ if(from->outkeylength != from->outcipher->key_len + from->outcipher->iv_len) {
+ logger(LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name,
+ from->hostname);
+ return false;
+ }
+ } else {
+ from->outcipher = NULL;
+ }
+
+ from->outmaclength = maclength;
+
+ if(digest) {
+ from->outdigest = EVP_get_digestbynid(digest);
+
+ if(!from->outdigest) {
+ logger(LOG_ERR, "Node %s (%s) uses unknown digest!", from->name,
+ from->hostname);
+ return false;
+ }
+
+ if(from->outmaclength > from->outdigest->md_size || from->outmaclength < 0) {
+ logger(LOG_ERR, "Node %s (%s) uses bogus MAC length!",
+ from->name, from->hostname);
+ return false;
+ }
+ } else {
+ from->outdigest = NULL;
+ }
+
+ if(compression < 0 || compression > 11) {
+ logger(LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
+ return false;
+ }
+
+ from->outcompression = compression;
+
+ if(from->outcipher)
+ if(!EVP_EncryptInit_ex(&from->outctx, from->outcipher, NULL, (unsigned char *)from->outkey, (unsigned char *)from->outkey + from->outcipher->key_len)) {
+ logger(LOG_ERR, "Error during initialisation of key from %s (%s): %s",
+ from->name, from->hostname, ERR_error_string(ERR_get_error(), NULL));
+ return false;
+ }
+
+ from->status.validkey = true;
+ from->sent_seqno = 0;
+
+ if(from->options & OPTION_PMTU_DISCOVERY && !from->mtuprobes)
+ send_mtu_probe(from);
+
+ return true;