+#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
+ if(sa->sa.sa_family == AF_INET6)
+ setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option);
+#endif
+
+#if defined(IP_DONTFRAG) && !defined(IP_DONTFRAGMENT)
+#define IP_DONTFRAGMENT IP_DONTFRAG
+#endif
+
+#if defined(SOL_IP) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
+ if(myself->options & OPTION_PMTU_DISCOVERY) {
+ option = IP_PMTUDISC_DO;
+ setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, (void *)&option, sizeof(option));
+ }
+#elif defined(IPPROTO_IP) && defined(IP_DONTFRAGMENT)
+ if(myself->options & OPTION_PMTU_DISCOVERY) {
+ option = 1;
+ setsockopt(nfd, IPPROTO_IP, IP_DONTFRAGMENT, (void *)&option, sizeof(option));
+ }
+#endif
+
+#if defined(SOL_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
+ if(myself->options & OPTION_PMTU_DISCOVERY) {
+ option = IPV6_PMTUDISC_DO;
+ setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, (void *)&option, sizeof(option));
+ }
+#elif defined(IPPROTO_IPV6) && defined(IPV6_DONTFRAG)
+ if(myself->options & OPTION_PMTU_DISCOVERY) {
+ option = 1;
+ setsockopt(nfd, IPPROTO_IPV6, IPV6_DONTFRAG, (void *)&option, sizeof(option));
+ }
+#endif
+
+ if (!bind_to_interface(nfd)) {
+ closesocket(nfd);
+ return -1;
+ }
+
+ if(bind(nfd, &sa->sa, SALEN(sa->sa))) {
+ closesocket(nfd);
+ addrstr = sockaddr2hostname(sa);
+ logger(LOG_ERR, "Can't bind to %s/udp: %s", addrstr, sockstrerror(sockerrno));
+ free(addrstr);
+ return -1;
+ }
+
+ return nfd;
+} /* int setup_vpn_in_socket */
+
+void retry_outgoing(outgoing_t *outgoing) {
+ outgoing->timeout += 5;
+
+ if(outgoing->timeout < mintimeout)
+ outgoing->timeout = mintimeout;
+
+ if(outgoing->timeout > maxtimeout)
+ outgoing->timeout = maxtimeout;
+
+ if(outgoing->event)
+ event_del(outgoing->event);
+ outgoing->event = new_event();
+ outgoing->event->handler = (event_handler_t) setup_outgoing_connection;
+ outgoing->event->time = now + outgoing->timeout;
+ outgoing->event->data = outgoing;
+ event_add(outgoing->event);
+
+ ifdebug(CONNECTIONS) logger(LOG_NOTICE,
+ "Trying to re-establish outgoing connection in %d seconds",
+ outgoing->timeout);