-int setup_myself(void)
-{
- config_t *cfg;
- subnet_t *subnet;
- char *name, *hostname, *mode, *afname, *cipher, *digest;
- struct addrinfo hint, *ai, *aip;
- int choice, err;
-cp
- myself = new_node();
- myself->connection = new_connection();
- init_configuration(&myself->connection->config_tree);
-
- asprintf(&myself->hostname, _("MYSELF"));
- asprintf(&myself->connection->hostname, _("MYSELF"));
-
- myself->connection->options = 0;
- myself->connection->protocol_version = PROT_CURRENT;
-
- if(!get_config_string(lookup_config(config_tree, "Name"), &name)) /* Not acceptable */
- {
- syslog(LOG_ERR, _("Name for tinc daemon required!"));
- return -1;
- }
-
- if(check_id(name))
- {
- syslog(LOG_ERR, _("Invalid name for myself!"));
- free(name);
- return -1;
- }
-
- myself->name = name;
- myself->connection->name = xstrdup(name);
-
-cp
- if(read_rsa_private_key())
- return -1;
-
- if(read_connection_config(myself->connection))
- {
- syslog(LOG_ERR, _("Cannot open host configuration file for myself!"));
- return -1;
- }
-
- if(read_rsa_public_key(myself->connection))
- return -1;
-cp
-
- if(check_rsa_key(myself->connection->rsa_key))
- {
- syslog(LOG_ERR, _("Invalid public/private keypair!"));
- return -1;
- }
-
- if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport))
- asprintf(&myport, "655");
-
-/* Read in all the subnets specified in the host configuration file */
-
- cfg = lookup_config(myself->connection->config_tree, "Subnet");
-
- while(cfg)
- {
- if(!get_config_subnet(cfg, &subnet))
- return -1;
-
- subnet_add(myself, subnet);
-
- cfg = lookup_config_next(myself->connection->config_tree, cfg);
- }
-
-cp
- /* Check some options */
-
- if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice))
- if(choice)
- myself->options |= OPTION_INDIRECT;
-
- if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice))
- if(choice)
- myself->options |= OPTION_TCPONLY;
-
- if(get_config_bool(lookup_config(myself->connection->config_tree, "IndirectData"), &choice))
- if(choice)
- myself->options |= OPTION_INDIRECT;
-
- if(get_config_bool(lookup_config(myself->connection->config_tree, "TCPOnly"), &choice))
- if(choice)
- myself->options |= OPTION_TCPONLY;
-
- if(myself->options & OPTION_TCPONLY)
- myself->options |= OPTION_INDIRECT;
-
- if(get_config_string(lookup_config(config_tree, "Mode"), &mode))
- {
- if(!strcasecmp(mode, "router"))
- routing_mode = RMODE_ROUTER;
- else if (!strcasecmp(mode, "switch"))
- routing_mode = RMODE_SWITCH;
- else if (!strcasecmp(mode, "hub"))
- routing_mode = RMODE_HUB;
- else
- {
- syslog(LOG_ERR, _("Invalid routing mode!"));
- return -1;
- }
- free(mode);
- }
- else
- routing_mode = RMODE_ROUTER;
-
- get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
+bool setup_myself(void) {
+ config_t *cfg;
+ subnet_t *subnet;
+ char *name, *hostname, *mode, *afname, *cipher, *digest;
+ char *fname = NULL;
+ char *address = NULL;
+ char *envp[5];
+ struct addrinfo *ai, *aip, hint = {0};
+ bool choice;
+ int i, err;
+ int replaywin_int;
+
+ myself = new_node();
+ myself->connection = new_connection();
+
+ myself->hostname = xstrdup("MYSELF");
+ myself->connection->hostname = xstrdup("MYSELF");
+
+ myself->connection->options = 0;
+ myself->connection->protocol_version = PROT_CURRENT;
+
+ if(!get_config_string(lookup_config(config_tree, "Name"), &name)) { /* Not acceptable */
+ logger(LOG_ERR, "Name for tinc daemon required!");
+ return false;
+ }
+
+ if(!check_id(name)) {
+ logger(LOG_ERR, "Invalid name for myself!");
+ free(name);
+ return false;
+ }
+
+ myself->name = name;
+ myself->connection->name = xstrdup(name);
+ xasprintf(&fname, "%s/hosts/%s", confbase, name);
+ read_config_options(config_tree, name);
+ read_config_file(config_tree, fname);
+ free(fname);
+
+ if(!read_rsa_private_key())
+ return false;
+
+ if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
+ myport = xstrdup("655");
+
+ 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);
+ sockaddr2str(&sa, NULL, &myport);
+ }
+
+ /* Read in all the subnets specified in the host configuration file */
+
+ cfg = lookup_config(config_tree, "Subnet");
+
+ while(cfg) {
+ if(!get_config_subnet(cfg, &subnet))
+ return false;
+
+ subnet_add(myself, subnet);
+
+ cfg = lookup_config_next(config_tree, cfg);
+ }
+
+ /* Check some options */
+
+ if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice) && choice)
+ myself->options |= OPTION_INDIRECT;
+
+ if(get_config_bool(lookup_config(config_tree, "TCPOnly"), &choice) && choice)
+ myself->options |= OPTION_TCPONLY;
+
+ if(myself->options & OPTION_TCPONLY)
+ myself->options |= OPTION_INDIRECT;
+
+ get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
+ get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets);
+ get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver);
+ strictsubnets |= tunnelserver;
+
+ if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) {
+ if(!strcasecmp(mode, "router"))
+ routing_mode = RMODE_ROUTER;
+ else if(!strcasecmp(mode, "switch"))
+ routing_mode = RMODE_SWITCH;
+ else if(!strcasecmp(mode, "hub"))
+ routing_mode = RMODE_HUB;
+ else {
+ logger(LOG_ERR, "Invalid routing mode!");
+ return false;
+ }
+ free(mode);
+ }
+
+ if(get_config_string(lookup_config(config_tree, "Forwarding"), &mode)) {
+ if(!strcasecmp(mode, "off"))
+ forwarding_mode = FMODE_OFF;
+ else if(!strcasecmp(mode, "internal"))
+ forwarding_mode = FMODE_INTERNAL;
+ else if(!strcasecmp(mode, "kernel"))
+ forwarding_mode = FMODE_KERNEL;
+ else {
+ logger(LOG_ERR, "Invalid forwarding mode!");
+ return false;
+ }
+ free(mode);
+ }
+
+ choice = true;
+ get_config_bool(lookup_config(config_tree, "PMTUDiscovery"), &choice);
+ if(choice)
+ myself->options |= OPTION_PMTU_DISCOVERY;
+
+ choice = true;
+ get_config_bool(lookup_config(config_tree, "ClampMSS"), &choice);
+ if(choice)
+ myself->options |= OPTION_CLAMP_MSS;
+
+ get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
+