+ myself->connection->rsa = read_rsa_private_key(&config_tree, NULL);
+
+ if(!myself->connection->rsa) {
+ if(experimental) {
+ logger(DEBUG_ALWAYS, LOG_WARNING, "Support for legacy protocol disabled.");
+ } else {
+ logger(DEBUG_ALWAYS, LOG_ERR, "No private keys available, cannot start tinc!");
+ return false;
+ }
+ }
+
+#endif
+
+ /* Ensure myport is numeric */
+
+ if(!atoi(myport)) {
+ struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
+ sockaddr_t sa;
+
+ if(!ai || !ai->ai_addr) {
+ return false;
+ }
+
+ free(myport);
+ memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
+ sockaddr2str(&sa, NULL, &myport);
+ }
+
+ /* Read in all the subnets specified in the host configuration file */
+
+ for(config_t *cfg = lookup_config(&config_tree, "Subnet"); cfg; cfg = lookup_config_next(&config_tree, cfg)) {
+ subnet_t *subnet;
+
+ if(!get_config_subnet(cfg, &subnet)) {
+ return false;
+ }
+
+ subnet_add(myself, subnet);
+ }
+
+ /* Check some options */
+
+ if(!setup_myself_reloadable()) {
+ return false;
+ }
+
+ get_config_bool(lookup_config(&config_tree, "StrictSubnets"), &strictsubnets);
+ get_config_bool(lookup_config(&config_tree, "TunnelServer"), &tunnelserver);
+ strictsubnets |= tunnelserver;
+
+ if(get_config_int(lookup_config(&config_tree, "MaxConnectionBurst"), &max_connection_burst)) {
+ if(max_connection_burst <= 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "MaxConnectionBurst cannot be negative!");
+ return false;
+ }
+ }
+
+ if(get_config_int(lookup_config(&config_tree, "UDPRcvBuf"), &udp_rcvbuf)) {
+ if(udp_rcvbuf < 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "UDPRcvBuf cannot be negative!");
+ return false;
+ }
+
+ udp_rcvbuf_warnings = true;
+ }
+
+ if(get_config_int(lookup_config(&config_tree, "UDPSndBuf"), &udp_sndbuf)) {
+ if(udp_sndbuf < 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "UDPSndBuf cannot be negative!");
+ return false;
+ }
+
+ udp_sndbuf_warnings = true;
+ }
+
+ get_config_int(lookup_config(&config_tree, "FWMark"), &fwmark);
+#ifndef SO_MARK
+
+ if(fwmark) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "FWMark not supported on this platform!");
+ return false;
+ }
+
+#endif
+
+ int replaywin_int;
+
+ if(get_config_int(lookup_config(&config_tree, "ReplayWindow"), &replaywin_int)) {
+ if(replaywin_int < 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "ReplayWindow cannot be negative!");
+ return false;
+ }
+
+ replaywin = (unsigned)replaywin_int;
+ sptps_replaywin = replaywin;
+ }
+
+#ifndef DISABLE_LEGACY
+ /* Generate packet encryption key */
+
+ char *cipher;
+
+ if(!get_config_string(lookup_config(&config_tree, "Cipher"), &cipher)) {
+ cipher = xstrdup("aes-256-cbc");
+ }
+
+ if(!strcasecmp(cipher, "none")) {
+ myself->incipher = NULL;
+ } else {
+ myself->incipher = cipher_alloc();
+
+ if(!cipher_open_by_name(myself->incipher, cipher)) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized cipher type!");
+ cipher_free(&myself->incipher);
+ free(cipher);
+ return false;
+ }
+ }
+
+ free(cipher);
+
+ timeout_add(&keyexpire_timeout, keyexpire_handler, &keyexpire_timeout, &(struct timeval) {
+ keylifetime, jitter()
+ });
+
+ /* Check if we want to use message authentication codes... */
+
+ int maclength = 4;
+ get_config_int(lookup_config(&config_tree, "MACLength"), &maclength);
+
+ if(maclength < 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Bogus MAC length!");
+ return false;
+ }
+
+ char *digest;
+
+ if(!get_config_string(lookup_config(&config_tree, "Digest"), &digest)) {
+ digest = xstrdup("sha256");
+ }
+
+ if(!strcasecmp(digest, "none")) {
+ myself->indigest = NULL;
+ } else {
+ myself->indigest = digest_alloc();
+
+ if(!digest_open_by_name(myself->indigest, digest, maclength)) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Unrecognized digest type!");
+ digest_free(&myself->indigest);
+ free(digest);
+ return false;
+ }
+ }
+
+ free(digest);
+#endif