+
+ free(rmode);
+ }
+
+ if(get_config_string(lookup_config(config_tree, "Forwarding"), &fmode)) {
+ if(!strcasecmp(fmode, "off")) {
+ forwarding_mode = FMODE_OFF;
+ } else if(!strcasecmp(fmode, "internal")) {
+ forwarding_mode = FMODE_INTERNAL;
+ } else if(!strcasecmp(fmode, "kernel")) {
+ forwarding_mode = FMODE_KERNEL;
+ } else {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Invalid forwarding mode!");
+ return false;
+ }
+
+ free(fmode);
+ }
+
+ choice = !(myself->options & OPTION_TCPONLY);
+ 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);
+ get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl);
+
+ if(get_config_string(lookup_config(config_tree, "Broadcast"), &bmode)) {
+ if(!strcasecmp(bmode, "no")) {
+ broadcast_mode = BMODE_NONE;
+ } else if(!strcasecmp(bmode, "yes") || !strcasecmp(bmode, "mst")) {
+ broadcast_mode = BMODE_MST;
+ } else if(!strcasecmp(bmode, "direct")) {
+ broadcast_mode = BMODE_DIRECT;
+ } else {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Invalid broadcast mode!");
+ return false;
+ }
+
+ free(bmode);
+ }
+
+ const char *const DEFAULT_BROADCAST_SUBNETS[] = { "ff:ff:ff:ff:ff:ff", "255.255.255.255", "224.0.0.0/4", "ff00::/8" };
+
+ for(size_t i = 0; i < sizeof(DEFAULT_BROADCAST_SUBNETS) / sizeof(*DEFAULT_BROADCAST_SUBNETS); i++) {
+ subnet_t *s = new_subnet();
+
+ if(!str2net(s, DEFAULT_BROADCAST_SUBNETS[i])) {
+ abort();
+ }
+
+ subnet_add(NULL, s);
+ }
+
+ for(config_t *cfg = lookup_config(config_tree, "BroadcastSubnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
+ subnet_t *s;
+
+ if(!get_config_subnet(cfg, &s)) {
+ continue;
+ }
+
+ subnet_add(NULL, s);
+ }
+
+#if !defined(IP_TOS)
+
+ if(priorityinheritance) {
+ logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform for IPv4 connections", "PriorityInheritance");
+ }
+
+#endif
+
+#if !defined(IPV6_TCLASS)
+
+ if(priorityinheritance) {
+ logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform for IPv6 connections", "PriorityInheritance");
+ }
+
+#endif
+
+ if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire)) {
+ macexpire = 600;
+ }
+
+ if(get_config_int(lookup_config(config_tree, "MaxTimeout"), &maxtimeout)) {
+ if(maxtimeout <= 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Bogus maximum timeout!");
+ return false;
+ }
+ } else {
+ maxtimeout = 900;
+ }
+
+ if(get_config_string(lookup_config(config_tree, "AddressFamily"), &afname)) {
+ if(!strcasecmp(afname, "IPv4")) {
+ addressfamily = AF_INET;
+ } else if(!strcasecmp(afname, "IPv6")) {
+ addressfamily = AF_INET6;
+ } else if(!strcasecmp(afname, "any")) {
+ addressfamily = AF_UNSPEC;
+ } else {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Invalid address family!");
+ return false;
+ }
+
+ free(afname);
+ }
+
+ get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
+
+ if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime)) {
+ keylifetime = 3600;
+ }
+
+ config_t *cfg = lookup_config(config_tree, "AutoConnect");
+
+ if(cfg) {
+ if(!get_config_bool(cfg, &autoconnect)) {
+ // Some backwards compatibility with when this option was an int
+ int val = 0;
+ get_config_int(cfg, &val);
+ autoconnect = val;
+ }
+ }
+
+ get_config_bool(lookup_config(config_tree, "DisableBuggyPeers"), &disablebuggypeers);
+
+ if(!get_config_int(lookup_config(config_tree, "InvitationExpire"), &invitation_lifetime)) {
+ invitation_lifetime = 604800; // 1 week
+ }
+
+ read_invitation_key();
+
+ return true;
+}
+
+/*
+ Add listening sockets.
+*/
+static bool add_listen_address(char *address, bool bindto) {
+ char *port = myport;
+
+ if(address) {
+ char *space = strchr(address, ' ');
+
+ if(space) {
+ *space++ = 0;
+ port = space;
+ }
+
+ if(!strcmp(address, "*")) {
+ *address = 0;
+ }