+
+ /* Forward it if necessary */
+
+ if(to != myself) {
+ if(tunnelserver)
+ return false;
+
+ return send_request(to->nexthop->connection, "%s", c->buffer);
+ }
+
+ /* Update our copy of the origin's packet key */
+
+ if(from->key)
+ free(from->key);
+
+ from->key = xstrdup(key);
+ from->keylength = strlen(key) / 2;
+ hex2bin(from->key, from->key, from->keylength);
+ from->key[from->keylength] = '\0';
+
+ from->status.validkey = true;
+ from->status.waitingforkey = false;
+ from->sent_seqno = 0;
+
+ /* Check and lookup cipher and digest algorithms */
+
+ if(cipher) {
+ from->cipher = EVP_get_cipherbynid(cipher);
+
+ if(!from->cipher) {
+ logger(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
+ from->hostname);
+ return false;
+ }
+
+ if(from->keylength != from->cipher->key_len + from->cipher->iv_len) {
+ logger(LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
+ from->hostname);
+ return false;
+ }
+ } else {
+ from->cipher = NULL;
+ }
+
+ from->maclength = maclength;
+
+ if(digest) {
+ from->digest = EVP_get_digestbynid(digest);
+
+ if(!from->digest) {
+ logger(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
+ from->hostname);
+ return false;
+ }
+
+ if(from->maclength > from->digest->md_size || from->maclength < 0) {
+ logger(LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
+ from->name, from->hostname);
+ return false;
+ }
+ } else {
+ from->digest = NULL;
+ }
+
+ if(compression < 0 || compression > 11) {
+ logger(LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
+ return false;
+ }
+
+ from->compression = compression;
+
+ if(from->cipher)
+ if(!EVP_EncryptInit_ex(&from->packet_ctx, from->cipher, NULL, from->key, from->key + from->cipher->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;
+ }
+
+ if(from->options & OPTION_PMTU_DISCOVERY && !from->mtuprobes)
+ send_mtu_probe(from);
+
+ flush_queue(from);
+
+ return true;