Go to the documentation of this file.
49 sf2gaf(
const unsigned int getaddr_flags,
50 const unsigned int sockflags)
67 void *network,
unsigned int *netbits,
68 int resolve_retry_seconds,
struct signal_info *sig_info,
71 char *endp, *sep, *var_host = NULL;
72 struct addrinfo *ai = NULL;
88 max_bits =
sizeof(in_addr_t) * 8;
93 max_bits =
sizeof(
struct in6_addr) * 8;
98 "Unsupported AF family passed to getaddrinfo for %s (%d)",
108 var_host = strdup(hostname);
112 "Can't allocate hostname buffer for getaddrinfo");
117 sep = strchr(var_host,
'/');
120 bits = strtoul(sep + 1, &endp, 10);
121 if ((*endp !=
'\0') || (bits > max_bits))
123 msg(msglevel,
"IP prefix '%s': invalid '/bits' spec (%s)", hostname,
131 resolve_retry_seconds, sig_info, af, &ai);
132 if ((ret == 0) && network)
134 struct in6_addr *ip6;
141 *ip4 = ((
struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr;
151 *ip6 = ((
struct sockaddr_in6 *)ai->ai_addr)->sin6_addr;
157 "Unsupported AF family for %s (%d)", var_host, af);
181 const char *hostname,
182 int resolve_retry_seconds,
190 resolve_retry_seconds, sig_info,
212 unsigned int *netbits,
int msglevel)
215 0, NULL, msglevel) < 0)
226 if (a == NULL && b == NULL)
230 else if (a == NULL || b == NULL)
246 const char *hostname,
247 const char *servname,
250 struct addrinfo **ai)
258 for (ph = dns_cache; ph; ph = ph->
next)
338 for (i = 0; i < l->
len; ++i)
342 int flags = preresolve_flags;
430 const char *hostname,
431 const char *servname,
432 int resolve_retry_seconds,
435 struct addrinfo **res)
437 struct addrinfo hints;
442 const char *print_hostname;
443 const char *print_servname;
447 ASSERT(hostname || servname);
452 print_servname = servname;
472 hints.ai_family = ai_family;
473 hints.ai_flags = AI_NUMERICHOST;
477 hints.ai_flags |= AI_PASSIVE;
482 hints.ai_socktype = SOCK_DGRAM;
486 hints.ai_socktype = SOCK_STREAM;
489 status = getaddrinfo(hostname, servname, &hints, res);
493 const int fail_wait_interval = 5;
496 ((resolve_retry_seconds + 4)/ fail_wait_interval);
507 print_hostname = hostname;
511 print_hostname =
"undefined";
514 fmt =
"RESOLVE: Cannot resolve host address: %s:%s (%s)";
516 && !resolve_retry_seconds)
518 fmt =
"RESOLVE: Cannot resolve host address: %s:%s (%s) "
519 "(I would have retried this name query if you had "
520 "specified the --resolv-retry option.)";
525 msg(msglevel,
"RESOLVE: Cannot parse IP address: %s:%s (%s)",
526 print_hostname, print_servname, gai_strerror(
status));
530 #ifdef ENABLE_MANAGEMENT
556 hints.ai_flags &= ~AI_NUMERICHOST;
558 "GETADDRINFO flags=0x%04x ai_family=%d ai_socktype=%d",
559 flags, hints.ai_family, hints.ai_socktype);
560 status = getaddrinfo(hostname, servname, &hints, res);
571 "RESOLVE: Ignored SIGUSR1 signal received during "
572 "DNS resolution attempt");
599 if (resolve_retries > 0)
610 if (--resolve_retries <= 0)
633 "WARNING: ignoring --remote-random-hostname because the "
634 "hostname is an IP address");
650 msg(level,
"RESOLVE: signal received during DNS resolution attempt");
664 unsigned int a, b, c, d;
667 if (sscanf(dotted_quad,
"%u.%u.%u.%u", &a, &b, &c, &d) == 4)
669 if (a < 256 && b < 256 && c < 256 && d < 256)
671 addr->s_addr = htonl(a<<24 | b<<16 | c<<8 | d);
695 if (strlen(dotted_quad) > 15)
704 const char *p = dotted_quad;
709 if (c >=
'0' && c <=
'9')
745 if (strlen(ipv6_text_addr) > INET6_ADDRSTRLEN)
753 return inet_pton( AF_INET6, ipv6_text_addr, &a6 ) == 1;
762 const size_t len = strlen(addr);
798 if (strlen(mac_addr) > 17)
807 const char *p = mac_addr;
812 if ( (c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f') || (c >=
'A' && c <=
'F') )
838 #if defined(SOL_SOCKET) && defined(SO_SNDBUF)
843 if (getsockopt(sd, SOL_SOCKET, SO_SNDBUF, (
void *) &val, &len) == 0
844 && len ==
sizeof(val))
855 #if defined(SOL_SOCKET) && defined(SO_SNDBUF)
856 if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (
void *) &size,
sizeof(size)) != 0)
858 msg(
M_WARN,
"NOTE: setsockopt SO_SNDBUF=%d failed", size);
866 #if defined(SOL_SOCKET) && defined(SO_RCVBUF)
871 if (getsockopt(sd, SOL_SOCKET, SO_RCVBUF, (
void *) &val, &len) == 0
872 && len ==
sizeof(val))
883 #if defined(SOL_SOCKET) && defined(SO_RCVBUF)
884 if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (
void *) &size,
sizeof(size)) != 0)
886 msg(
M_WARN,
"NOTE: setsockopt SO_RCVBUF=%d failed", size);
911 msg(
D_OSBUF,
"Socket Buffers: R=[%d->%d] S=[%d->%d]",
926 #if defined(_WIN32) || (defined(IPPROTO_TCP) && defined(TCP_NODELAY))
927 if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (
void *) &state,
sizeof(state)) != 0)
929 msg(
M_WARN,
"NOTE: setsockopt TCP_NODELAY=%d failed", state);
934 dmsg(
D_OSBUF,
"Socket flags: TCP_NODELAY=%d succeeded", state);
938 msg(
M_WARN,
"NOTE: setsockopt TCP_NODELAY=%d failed (No kernel support)", state);
946 #if defined(TARGET_LINUX) && HAVE_DECL_SO_MARK
947 if (mark && setsockopt(sd, SOL_SOCKET, SO_MARK, (
void *) &mark,
sizeof(mark)) != 0)
949 msg(
M_WARN,
"NOTE: setsockopt SO_MARK=%d failed", mark);
1004 ASSERT(addrinfo->ai_socktype == SOCK_STREAM);
1006 if ((sd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)
1008 msg(
M_ERR,
"Cannot create TCP socket");
1015 if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR,
1016 (
void *) &on,
sizeof(on)) < 0)
1018 msg(
M_ERR,
"TCP: Cannot setsockopt SO_REUSEADDR on TCP socket");
1036 ASSERT(addrinfo->ai_socktype == SOCK_DGRAM);
1038 if ((sd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)
1040 msg(
M_ERR,
"UDP: Cannot create UDP/UDP6 socket");
1042 #if ENABLE_IP_PKTINFO
1046 if (addrinfo->ai_family == AF_INET)
1048 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
1049 if (setsockopt(sd,
SOL_IP, IP_PKTINFO,
1050 (
void *)&pad,
sizeof(pad)) < 0)
1052 msg(
M_ERR,
"UDP: failed setsockopt for IP_PKTINFO");
1054 #elif defined(IP_RECVDSTADDR)
1055 if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR,
1056 (
void *)&pad,
sizeof(pad)) < 0)
1058 msg(
M_ERR,
"UDP: failed setsockopt for IP_RECVDSTADDR");
1061 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
1064 else if (addrinfo->ai_family == AF_INET6)
1066 #ifndef IPV6_RECVPKTINFO
1067 if (setsockopt(sd, IPPROTO_IPV6, IPV6_PKTINFO,
1068 (
void *)&pad,
sizeof(pad)) < 0)
1070 if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
1071 (
void *)&pad,
sizeof(pad)) < 0)
1073 {
msg(
M_ERR,
"UDP: failed setsockopt for IPV6_RECVPKTINFO");}
1094 ai_family,
"SOCKS",
false);
1108 if (addr->ai_protocol == IPPROTO_UDP || addr->ai_socktype == SOCK_DGRAM)
1120 struct addrinfo addrinfo_tmp = *addr;
1121 addrinfo_tmp.ai_socktype = SOCK_STREAM;
1122 addrinfo_tmp.ai_protocol = IPPROTO_TCP;
1126 else if (addr->ai_protocol == IPPROTO_TCP || addr->ai_socktype == SOCK_STREAM)
1136 sock->
info.
af = addr->ai_family;
1144 #if defined(TARGET_LINUX)
1148 if (setsockopt(sock->
sd, SOL_SOCKET, SO_BINDTODEVICE, sock->
bind_dev, strlen(sock->
bind_dev) + 1) != 0)
1159 #ifdef TARGET_ANDROID
1161 protect_fd_nonlocal(
int fd,
const struct sockaddr *addr)
1165 msg(
M_FATAL,
"Required management interface not available.");
1179 management_android_control(
management,
"PROTECTFD", __func__);
1188 const struct addrinfo *local,
1190 bool do_set_nonblock)
1196 msg(
M_INFO,
"Listening for incoming TCP connection on %s",
1200 msg(
M_ERR,
"TCP: listen() failed");
1205 if (do_set_nonblock)
1223 socklen_t remote_len =
sizeof(act->
dest.
addr);
1230 new_sd = getpeername(sd, &act->
dest.
addr.
sa, &remote_len);
1243 new_sd = accept(sd, &act->
dest.
addr.
sa, &remote_len);
1262 else if (remote_len_af && remote_len != remote_len_af)
1264 msg(
D_LINK_ERRORS,
"TCP: Received strange incoming connection with unknown address length=%d", remote_len);
1281 msg(
M_INFO,
"TCP connection established with %s",
1289 const char *remote_dynamic,
1290 const struct addrinfo *local,
1293 volatile int *signal_received)
1314 status = select(sd + 1, &reads, NULL, NULL, &tv);
1317 if (*signal_received)
1338 struct addrinfo *ai = NULL;
1342 remote_verify.
addr.
sa.sa_family, &ai);
1348 "TCP NOTE: Rejected connection attempt from %s due to --remote setting",
1352 msg(
M_ERR,
"TCP: close socket failed (new_sd)");
1370 msg(
M_ERR,
"TCP: close socket failed (sd)");
1381 struct addrinfo *local,
1395 struct addrinfo *cur;
1401 for (cur = local; cur; cur = cur->ai_next)
1403 if (cur->ai_family == ai_family)
1410 msg(
M_FATAL,
"%s: Socket bind failed: Addr to bind has no %s record",
1414 if (ai_family == AF_INET6)
1416 int v6only = ipv6only ? 1 : 0;
1418 msg(
M_INFO,
"setsockopt(IPV6_V6ONLY=%d)", v6only);
1419 if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, (
void *) &v6only,
sizeof(v6only)))
1424 if (bind(sd, cur->ai_addr, cur->ai_addrlen))
1435 const struct sockaddr *remote,
1436 int connect_timeout,
1437 volatile int *signal_received)
1441 #ifdef TARGET_ANDROID
1442 protect_fd_nonlocal(sd, remote);
1462 struct pollfd fds[1];
1464 fds[0].events = POLLOUT;
1465 status = poll(fds, 1, (connect_timeout > 0) ? 1000 : 0);
1472 tv.tv_sec = (connect_timeout > 0) ? 1 : 0;
1475 status = select(sd + 1, NULL, &writes, NULL, &tv);
1477 if (signal_received)
1480 if (*signal_received)
1493 if (--connect_timeout < 0)
1512 if (getsockopt(sd, SOL_SOCKET, SO_ERROR, (
void *) &val, &len) == 0
1513 && len ==
sizeof(val))
1535 if (ai->ai_family == AF_INET)
1538 *((
struct sockaddr_in *) ai->ai_addr);
1540 else if (ai->ai_family == AF_INET6)
1543 *((
struct sockaddr_in6 *) ai->ai_addr);
1554 const struct sockaddr *dest,
1555 const int connect_timeout,
1561 msg(
M_INFO,
"Attempting to establish TCP connection with %s",
1564 #ifdef ENABLE_MANAGEMENT
1598 msg(
M_INFO,
"TCP connection established with %s",
1614 const unsigned int sockflags,
const int proto);
1686 msg(
M_FATAL,
"getaddrinfo() failed for local \"%s:%s\": %s",
1698 const char **remote_dynamic,
1701 volatile int *signal_received = sig_info ? &sig_info->
signal_received : NULL;
1712 struct addrinfo *ai;
1726 else if (phase == 1)
1738 else if (phase == 2)
1764 retry, sig_info, sock->
info.
af, &ai);
1773 "RESOLVE_REMOTE flags=0x%04x phase=%d rrs=%d sig=%d status=%d",
1777 signal_received ? *signal_received : -1,
1780 if (signal_received && *signal_received)
1786 if (signal_received)
1799 msg(
M_INFO,
"TCP/UDP: Preserving recently used remote address: %s",
1803 *remote_dynamic = NULL;
1840 const char *remote_host = o->
ce.
remote;
1855 sock->gremlin = o->gremlin;
1863 if (o->port_share_host && o->port_share_port)
1955 #if EXTENDED_SOCKET_ERROR_CAPABILITY
1957 set_sock_extended_error_passing(sock->
sd, sock->
info.
af);
1975 struct addrinfo *cur;
1978 if (!ai_family || ai_family == cur->ai_family)
1984 msg(msglevel,
"%s link local (bound): %s",
1990 msg(msglevel,
"%s link local: (not bound)",
1995 msg(msglevel,
"%s link remote: %s",
2050 bool proxy_retry =
false;
2088 }
while (proxy_retry);
2175 const char *remote_dynamic = NULL;
2183 sig_save = *sig_info;
2230 if (sock->
info.
af == AF_UNSPEC)
2232 msg(
M_WARN,
"Could not determine IPv4/IPv6 protocol. Using %s",
2244 msg(
M_WARN,
"Could not determine IPv4/IPv6 protocol");
2245 register_signal(sig_info, SIGUSR1,
"Could not determine IPv4/IPv6 protocol");
2267 #ifdef TARGET_ANDROID
2302 const int gremlin = GREMLIN_CONNECTION_FLOOD_LEVEL(sock->gremlin);
2304 const int gremlin = 0;
2314 msg(
D_LOW,
"TCP/UDP: Closing socket");
2373 const char *common_name,
2403 msg(
M_WARN,
"WARNING: ipchange plugin call failed");
2427 struct addrinfo *ai;
2434 "TCP/UDP: Incoming packet rejected from %s[%d], expected peer address: %s (allow this incoming source address/port by removing --remote or adding --float)",
2482 return ntohl(((
struct sockaddr_in *)lsa->
current_remote->ai_addr)
2491 const struct in6_addr *
2513 return &(((
struct sockaddr_in6 *)lsa->
current_remote->ai_addr)->sin6_addr);
2574 const unsigned int sockflags,
2650 if (length_added > 0)
2652 sb->
buf.
len += length_added;
2662 if (sb->port_share_state == PS_ENABLED)
2664 if (!is_openvpn_protocol(&sb->
buf))
2667 sb->port_share_state = PS_FOREIGN;
2673 sb->port_share_state = PS_DISABLED;
2683 msg(
M_WARN,
"WARNING: Bad encapsulated packet length from peer (%d), which must be > 0 and <= %d -- please ensure that --tun-mtu or --link-mtu is equal on both peers -- this condition could also indicate a possible active attack on the TCP link -- [Attempting restart...]", sb->
len, sb->
maxlen);
2743 const char *separator,
2744 const unsigned int flags,
2748 bool addr_is_defined =
false;
2749 char hostaddr[NI_MAXHOST] =
"";
2750 char servname[NI_MAXSERV] =
"";
2753 socklen_t salen = 0;
2754 switch (sa->sa_family)
2761 salen =
sizeof(
struct sockaddr_in);
2762 addr_is_defined = ((
struct sockaddr_in *) sa)->sin_addr.s_addr != 0;
2770 salen =
sizeof(
struct sockaddr_in6);
2771 addr_is_defined = !IN6_IS_ADDR_UNSPECIFIED(&((
struct sockaddr_in6 *) sa)->sin6_addr);
2777 return "[AF_UNSPEC]";
2788 status = getnameinfo(sa, salen, hostaddr,
sizeof(hostaddr),
2789 servname,
sizeof(servname), NI_NUMERICHOST | NI_NUMERICSERV);
2799 if (addr_is_defined)
2829 #define IF_NAMESIZE 16
2834 const char *separator,
2835 const unsigned int flags,
2842 #if ENABLE_IP_PKTINFO
2853 sa.addr.in4.sin_family = AF_INET;
2854 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
2855 sa.addr.in4.sin_addr = act->pi.in4.ipi_spec_dst;
2856 if_indextoname(act->pi.in4.ipi_ifindex, ifname);
2857 #elif defined(IP_RECVDSTADDR)
2858 sa.addr.in4.sin_addr = act->pi.in4;
2861 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
2871 struct sockaddr_in6 sin6;
2872 char buf[INET6_ADDRSTRLEN] =
"[undef]";
2874 sin6.sin6_family = AF_INET6;
2875 sin6.sin6_addr = act->pi.in6.ipi6_addr;
2876 if_indextoname(act->pi.in6.ipi6_ifindex, ifname);
2877 if (getnameinfo((
struct sockaddr *)&sin6,
sizeof(
struct sockaddr_in6),
2878 buf,
sizeof(buf), NULL, 0, NI_NUMERICHOST) == 0)
2880 buf_printf(&out,
" (via %s%%%s)", buf, ifname);
2884 buf_printf(&out,
" (via [getnameinfo() err]%%%s)", ifname);
2907 char *out =
gc_malloc(INET_ADDRSTRLEN,
true, gc);
2912 ia.s_addr = (flags &
IA_NET_ORDER) ? addr : htonl(addr);
2914 inet_ntop(AF_INET, &ia, out, INET_ADDRSTRLEN);
2926 char *out =
gc_malloc(INET6_ADDRSTRLEN,
true, gc);
2928 if (memcmp(&a6, &in6addr_any,
sizeof(a6)) != 0
2931 inet_ntop(AF_INET6, &a6, out, INET6_ADDRSTRLEN);
2948 #define UINT8_MAX 0xff
2959 for (i = 15; i>=0 && add > 0; i--)
2962 register uint32_t h;
2964 h = (
unsigned char) base.s6_addr[i];
2970 carry = ((h & 0xff) + (add & 0xff)) >> 8;
2971 add = (add>>8) + carry;
2982 char buf[INET6_ADDRSTRLEN];
2983 switch (addr->
addr.
sa.sa_family)
2988 snprintf(name_buf,
sizeof(name_buf),
"%s_ip", name_prefix);
2992 snprintf(name_buf,
sizeof(name_buf),
"%s", name_prefix);
2995 inet_ntop(AF_INET, &addr->
addr.
in4.sin_addr, buf,
sizeof(buf));
3000 snprintf(name_buf,
sizeof(name_buf),
"%s_port", name_prefix);
3006 if (IN6_IS_ADDR_V4MAPPED( &addr->
addr.
in6.sin6_addr ))
3009 memcpy(&ia.s_addr, &addr->
addr.
in6.sin6_addr.s6_addr[12],
3011 snprintf(name_buf,
sizeof(name_buf),
"%s_ip", name_prefix);
3012 inet_ntop(AF_INET, &ia, buf,
sizeof(buf));
3016 snprintf(name_buf,
sizeof(name_buf),
"%s_ip6", name_prefix);
3017 inet_ntop(AF_INET6, &addr->
addr.
in6.sin6_addr, buf,
sizeof(buf));
3023 snprintf(name_buf,
sizeof(name_buf),
"%s_port", name_prefix);
3037 si.
addr.
in4.sin_family = AF_INET;
3045 const char *name_prefix,
3046 const struct in6_addr *
addr,
3047 const unsigned int flags)
3053 si.
addr.
in6.sin6_family = AF_INET6;
3061 const char *name_prefix,
3063 const unsigned int flags)
3081 {
"proto-uninitialized",
"proto-NONE", AF_UNSPEC,
PROTO_NONE},
3146 return "[unknown protocol]";
3171 case AF_INET:
return "AF_INET";
3173 case AF_INET6:
return "AF_INET6";
3202 return "TCPv4_SERVER";
3207 return "TCPv4_CLIENT";
3221 msg(
M_FATAL,
"ERROR: received strange incoming packet with an address length of %d -- we only accept address lengths of %d.",
3245 msg(
M_INFO,
"BUG: link_socket_read_tcp(): sock->sd==-1, reset client instance" );
3247 return buf->
len = 0;
3278 return buf->
len = 0;
3284 #if ENABLE_IP_PKTINFO
3289 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
3290 #define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \
3291 CMSG_SPACE(sizeof(struct in_pktinfo)) )
3293 #define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \
3294 CMSG_SPACE(sizeof(struct in_addr)) )
3298 link_socket_read_udp_posix_recvmsg(
struct link_socket *sock,
3303 uint8_t pktinfo_buf[PKTINFO_BUF_SIZE];
3304 struct msghdr mesg = {0};
3305 socklen_t fromlen =
sizeof(from->
dest.
addr);
3309 iov.iov_base =
BPTR(buf);
3311 mesg.msg_iov = &iov;
3312 mesg.msg_iovlen = 1;
3314 mesg.msg_namelen = fromlen;
3315 mesg.msg_control = pktinfo_buf;
3316 mesg.msg_controllen =
sizeof pktinfo_buf;
3317 buf->
len = recvmsg(sock->
sd, &mesg, 0);
3320 struct cmsghdr *cmsg;
3321 fromlen = mesg.msg_namelen;
3322 cmsg = CMSG_FIRSTHDR(&mesg);
3324 && CMSG_NXTHDR(&mesg, cmsg) == NULL
3326 && cmsg->cmsg_level ==
SOL_IP
3327 && cmsg->cmsg_type == IP_PKTINFO
3328 && cmsg->cmsg_len >= CMSG_LEN(
sizeof(
struct in_pktinfo)) )
3329 #elif defined(IP_RECVDSTADDR)
3330 && cmsg->cmsg_level == IPPROTO_IP
3331 && cmsg->cmsg_type == IP_RECVDSTADDR
3332 && cmsg->cmsg_len >= CMSG_LEN(
sizeof(
struct in_addr)) )
3334 #error
ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
3337 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
3338 struct in_pktinfo *pkti = (
struct in_pktinfo *) CMSG_DATA(cmsg);
3339 from->pi.in4.ipi_ifindex = pkti->ipi_ifindex;
3340 from->pi.in4.ipi_spec_dst = pkti->ipi_spec_dst;
3341 #elif defined(IP_RECVDSTADDR)
3342 from->pi.in4 = *(
struct in_addr *) CMSG_DATA(cmsg);
3344 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
3347 else if (cmsg != NULL
3348 && CMSG_NXTHDR(&mesg, cmsg) == NULL
3349 && cmsg->cmsg_level == IPPROTO_IPV6
3350 && cmsg->cmsg_type == IPV6_PKTINFO
3351 && cmsg->cmsg_len >= CMSG_LEN(
sizeof(
struct in6_pktinfo)) )
3353 struct in6_pktinfo *pkti6 = (
struct in6_pktinfo *) CMSG_DATA(cmsg);
3354 from->pi.in6.ipi6_ifindex = pkti6->ipi6_ifindex;
3355 from->pi.in6.ipi6_addr = pkti6->ipi6_addr;
3357 else if (cmsg != NULL)
3359 msg(
M_WARN,
"CMSG received that cannot be parsed (cmsg_level=%d, cmsg_type=%d, cmsg=len=%d)", (
int)cmsg->cmsg_level, (
int)cmsg->cmsg_type, (
int)cmsg->cmsg_len );
3368 link_socket_read_udp_posix(
struct link_socket *sock,
3372 socklen_t fromlen =
sizeof(from->
dest.
addr);
3378 #if ENABLE_IP_PKTINFO
3382 fromlen = link_socket_read_udp_posix_recvmsg(sock, buf, from);
3389 if (buf->
len >= 0 && expectedlen && fromlen != expectedlen)
3415 return link_socket_write_tcp_posix(sock, buf, to);
3419 #if ENABLE_IP_PKTINFO
3422 link_socket_write_udp_posix_sendmsg(
struct link_socket *sock,
3428 struct cmsghdr *cmsg;
3429 uint8_t pktinfo_buf[PKTINFO_BUF_SIZE];
3431 iov.iov_base =
BPTR(buf);
3432 iov.iov_len =
BLEN(buf);
3433 mesg.msg_iov = &iov;
3434 mesg.msg_iovlen = 1;
3440 mesg.msg_namelen =
sizeof(
struct sockaddr_in);
3441 mesg.msg_control = pktinfo_buf;
3443 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
3444 mesg.msg_controllen = CMSG_SPACE(
sizeof(
struct in_pktinfo));
3445 cmsg = CMSG_FIRSTHDR(&mesg);
3446 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_pktinfo));
3447 cmsg->cmsg_level =
SOL_IP;
3448 cmsg->cmsg_type = IP_PKTINFO;
3450 struct in_pktinfo *pkti;
3451 pkti = (
struct in_pktinfo *) CMSG_DATA(cmsg);
3452 pkti->ipi_ifindex = to->pi.in4.ipi_ifindex;
3453 pkti->ipi_spec_dst = to->pi.in4.ipi_spec_dst;
3454 pkti->ipi_addr.s_addr = 0;
3456 #elif defined(IP_RECVDSTADDR)
3457 ASSERT( CMSG_SPACE(
sizeof(
struct in_addr)) <=
sizeof(pktinfo_buf) );
3458 mesg.msg_controllen = CMSG_SPACE(
sizeof(
struct in_addr));
3459 cmsg = CMSG_FIRSTHDR(&mesg);
3460 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_addr));
3461 cmsg->cmsg_level = IPPROTO_IP;
3462 cmsg->cmsg_type = IP_RECVDSTADDR;
3463 *(
struct in_addr *) CMSG_DATA(cmsg) = to->pi.in4;
3465 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
3472 struct in6_pktinfo *pkti6;
3474 mesg.msg_namelen =
sizeof(
struct sockaddr_in6);
3476 ASSERT( CMSG_SPACE(
sizeof(
struct in6_pktinfo)) <=
sizeof(pktinfo_buf) );
3477 mesg.msg_control = pktinfo_buf;
3478 mesg.msg_controllen = CMSG_SPACE(
sizeof(
struct in6_pktinfo));
3480 cmsg = CMSG_FIRSTHDR(&mesg);
3481 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in6_pktinfo));
3482 cmsg->cmsg_level = IPPROTO_IPV6;
3483 cmsg->cmsg_type = IPV6_PKTINFO;
3485 pkti6 = (
struct in6_pktinfo *) CMSG_DATA(cmsg);
3486 pkti6->ipi6_ifindex = to->pi.in6.ipi6_ifindex;
3487 pkti6->ipi6_addr = to->pi.in6.ipi6_addr;
3493 return sendmsg(sock->
sd, &mesg, 0);
3509 return GetLastError();
3512 return WSAGetLastError();
3539 wsabuf[0].len = maxsize ? maxsize :
BLEN(&sock->
reads.
buf);
3550 status = ReadFile((HANDLE)sock->
sd, wsabuf[0].buf, wsabuf[0].len,
3602 dmsg(
D_WIN32_IO,
"WIN32 I/O: Socket Receive immediate return [%d,%d]",
3603 (
int) wsabuf[0].len,
3609 if (
status == WSA_IO_PENDING)
3614 (
int) wsabuf[0].len);
3623 (
int) wsabuf[0].len,
3655 status = WriteFile((HANDLE)sock->
sd, wsabuf[0].buf, wsabuf[0].len,
3717 dmsg(
D_WIN32_IO,
"WIN32 I/O: Socket Send immediate return [%d,%d]",
3718 (
int) wsabuf[0].len,
3725 if (
status == WSA_IO_PENDING ||
status == ERROR_IO_PENDING)
3730 (
int) wsabuf[0].len);
3740 (
int) wsabuf[0].len,
3809 dmsg(
D_WIN32_IO,
"WIN32 I/O: Completion non-queued success [%d]", ret);
3836 case sizeof(
struct sockaddr_in):
3837 case sizeof(struct sockaddr_in6):
3840 case sizeof(struct sockaddr_in6)-4:
3847 switch (io->addr.sin_family)
3880 unsigned int rwflags,
3882 unsigned int *persistent)
3900 if (!persistent || *persistent != rwflags)
3905 *persistent = rwflags;
3924 #if UNIX_SOCK_SUPPORT
3931 sockaddr_unix_name(
const struct sockaddr_un *local,
const char *
null)
3933 if (local && local->sun_family == PF_UNIX)
3935 return local->sun_path;
3944 create_socket_unix(
void)
3948 if ((sd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
3950 msg(
M_ERR,
"Cannot create unix domain socket");
3962 struct sockaddr_un *local,
3966 const mode_t orig_umask = umask(0);
3968 if (bind(sd, (
struct sockaddr *) local,
sizeof(
struct sockaddr_un)))
3971 "%s: Socket bind[%d] failed on unix domain socket %s",
3974 sockaddr_unix_name(local,
"NULL"));
3983 struct sockaddr_un *remote)
3985 socklen_t remote_len =
sizeof(
struct sockaddr_un);
3989 ret = accept(sd, (
struct sockaddr *) remote, &remote_len);
4001 struct sockaddr_un *remote)
4003 int status = connect(sd, (
struct sockaddr *) remote,
sizeof(
struct sockaddr_un));
4012 sockaddr_unix_init(
struct sockaddr_un *local,
const char *path)
4014 local->sun_family = PF_UNIX;
4015 strncpynt(local->sun_path, path,
sizeof(local->sun_path));
4019 socket_delete_unix(
const struct sockaddr_un *local)
4021 const char *name = sockaddr_unix_name(local, NULL);
4022 if (name && strlen(name))
4031 #ifdef HAVE_GETPEEREID
4034 if (getpeereid(sd, &u, &g) == -1)
4047 #elif defined(SO_PEERCRED)
4048 struct ucred peercred;
4049 socklen_t so_len =
sizeof(peercred);
4050 if (getsockopt(sd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1)
4056 *uid = peercred.uid;
4060 *gid = peercred.gid;
char * overlapped_io_state_ascii(const struct overlapped_io *o)
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
static bool buf_safe(const struct buffer *buf, size_t len)
#define GETADDR_FATAL_ON_SIGNAL
void establish_socks_proxy_udpassoc(struct socks_proxy_info *p, socket_descriptor_t ctrl_sd, socket_descriptor_t udp_sd, struct openvpn_sockaddr *relay_addr, struct event_timeout *server_poll_timeout, struct signal_info *sig_info)
static void socket_frame_init(const struct frame *frame, struct link_socket *sock)
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
static void resolve_remote(struct link_socket *sock, int phase, const char **remote_dynamic, struct signal_info *sig_info)
volatile int signal_received
#define GETADDR_WARN_ON_SIGNAL
static void stream_buf_get_next(struct stream_buf *sb, struct buffer *buf)
union openvpn_sockaddr::@14 addr
static bool socket_is_dco_win(const struct link_socket *s)
Returns true if we are on Windows and this link is running on DCO-WIN.
static bool buf_read(struct buffer *src, void *dest, int size)
struct overlapped_io reads
const struct link_socket * accept_from
static struct gc_arena gc_new(void)
void gc_addspecial(void *addr, void(*free_function)(void *), struct gc_arena *a)
#define GETADDR_RANDOMIZE
static const char * print_sockaddr(const struct sockaddr *addr, struct gc_arena *gc)
bool ipv6_addr_safe(const char *ipv6_text_addr)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
static int buf_forward_capacity_total(const struct buffer *buf)
int len
Length in bytes of the actual content within the allocated memory.
const char * proto2ascii_all(struct gc_arena *gc)
const char * socks_proxy_server
static void buf_reset(struct buffer *buf)
static int socket_get_rcvbuf(socket_descriptor_t sd)
void sd_close(socket_descriptor_t *sd)
#define PS_DONT_SHOW_ADDR
struct tuntap * tuntap
Tun/tap virtual network interface.
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
void management_sleep(const int n)
A sleep function that services the management layer for n seconds rather than doing nothing.
static bool buf_copy_excess(struct buffer *dest, struct buffer *src, int len)
#define buf_init(buf, offset)
Contains all state information for one tunnel.
int socket_recv_queue(struct link_socket *sock, int maxsize)
static unsigned int sf2gaf(const unsigned int getaddr_flags, const unsigned int sockflags)
#define static_assert(expr, diagnostic)
struct link_socket_addr * lsa
const char * proto_remote(int proto, bool remote)
struct addrinfo * bind_local
struct plugin_list * plugins
List of plug-ins.
#define PS_DONT_SHOW_FAMILY
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
bool ip_addr_dotted_quad_safe(const char *dotted_quad)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static int openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook)
Will run a script and return the exit code of the script if between 0 and 255, -1 otherwise.
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
void setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct openvpn_sockaddr *addr, const unsigned int flags)
struct tuntap create_dco_handle(const char *devname, struct gc_arena *gc)
static void bind_local(struct link_socket *sock, const sa_family_t ai_family)
struct connection_entry ce
static void phase2_tcp_client(struct link_socket *sock, struct signal_info *sig_info)
struct http_proxy_options options
struct addrinfo * current_remote
const char * addr_family_name(int af)
static bool socket_set_rcvbuf(socket_descriptor_t sd, int size)
bool ip_or_dns_addr_safe(const char *addr, const bool allow_fqdn)
void establish_socks_proxy_passthru(struct socks_proxy_info *p, socket_descriptor_t sd, const char *host, const char *servname, struct event_timeout *server_poll_timeout, struct signal_info *sig_info)
static bool buf_copy(struct buffer *dest, const struct buffer *src)
#define SA_SET_IF_NONZERO
static void stream_buf_close(struct stream_buf *sb)
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
#define GETADDR_MENTION_RESOLVE_RETRY
socket_descriptor_t ctrl_sd
int openvpn_inet_aton(const char *dotted_quad, struct in_addr *addr)
#define SF_GETADDRINFO_DGRAM
static void stream_buf_get_final(struct stream_buf *sb, struct buffer *buf)
Packet geometry parameters.
static void socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size *sbs)
#define IOSTATE_IMMEDIATE_RETURN
static bool link_socket_connection_oriented(const struct link_socket *sock)
static void socket_connect(socket_descriptor_t *sd, const struct sockaddr *dest, const int connect_timeout, struct signal_info *sig_info)
int resolve_retry_seconds
void setenv_int(struct env_set *es, const char *name, int value)
static void resolve_bind_local(struct link_socket *sock, const sa_family_t af)
int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, struct signal_info *sig_info, int ai_family, struct addrinfo **res)
#define CC_ALNUM
alphanumeric isalnum()
static void addr_zero_host(struct openvpn_sockaddr *addr)
struct rw_handle listen_handle
void throw_signal_soft(const int signum, const char *signal_text)
Throw a soft global signal.
static socket_descriptor_t create_socket_udp(struct addrinfo *addrinfo, const unsigned int flags)
static int plugin_call(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es)
unsigned short sa_family_t
unsigned int rwflags_debug
bool stream_buf_read_setup_dowork(struct link_socket *sock)
const char * proxy_dest_host
bool establish_http_proxy_passthru(struct http_proxy_info *p, socket_descriptor_t sd, const char *host, const char *port, struct event_timeout *server_poll_timeout, struct buffer *lookahead, struct signal_info *sig_info)
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
int get_server_poll_remaining_time(struct event_timeout *server_poll_timeout)
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
struct context_2 c2
Level 2 context.
#define HAVE_IPI_SPEC_DST
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
static event_t socket_event_handle(const struct link_socket *s)
const char * socks_proxy_port
static int get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network, unsigned int *netbits, int resolve_retry_seconds, struct signal_info *sig_info, int msglevel)
static bool link_socket_actual_defined(const struct link_socket_actual *act)
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
void overlapped_io_close(struct overlapped_io *o)
const char * ip_remote_hint
static bool defined_net_event_win32(const struct rw_handle *event)
bool mac_addr_safe(const char *mac_addr)
struct gc_arena gc
Garbage collection arena for allocations done in the scope of this context structure.
const char * print_link_socket_actual_ex(const struct link_socket_actual *act, const char *separator, const unsigned int flags, struct gc_arena *gc)
void link_socket_bad_outgoing_addr(void)
struct link_socket_addr link_socket_addr
Local and remote addresses on the external network.
struct socks_proxy_info * socks_proxy
void init_net_event_win32(struct rw_handle *event, long network_events, socket_descriptor_t sd, unsigned int flags)
struct sockaddr_in6 addr6
#define ALLOC_OBJ(dptr, type)
#define RESOLV_RETRY_INFINITE
#define OPENVPN_PLUGIN_IPCHANGE
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
int ascii2proto(const char *proto_name)
static bool addrlist_match(const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
#define OPENVPN_STATE_TCP_CONNECT
static bool stream_buf_added(struct stream_buf *sb, int length_added)
static int get_cached_dns_entry(struct cached_dns_entry *dns_cache, const char *hostname, const char *servname, int ai_family, int resolve_flags, struct addrinfo **ai)
static bool socket_set_flags(socket_descriptor_t sd, unsigned int sockflags)
void link_socket_connection_initiated(struct link_socket_info *info, const struct link_socket_actual *act, const char *common_name, struct env_set *es)
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
static int SocketHandleGetLastError(sockethandle_t sh)
static void phase2_tcp_server(struct link_socket *sock, const char *remote_dynamic, struct signal_info *sig_info)
#define LS_MODE_TCP_ACCEPT_FROM
struct options options
Options loaded from command line or configuration file.
static int do_preresolve_host(struct context *c, const char *hostname, const char *servname, const int af, const int flags)
static void linksock_print_addr(struct link_socket *sock)
static void openvpn_fd_set(socket_descriptor_t fd, fd_set *setp)
#define GETADDR_UPDATE_MANAGEMENT_STATE
static void ipchange_fmt(const bool include_cmd, struct argv *argv, const struct link_socket_info *info, struct gc_arena *gc)
struct event_timeout * server_poll_timeout
void throw_signal(const int signum)
Throw a hard signal.
bool residual_fully_formed
struct cached_dns_entry * next
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
void set_nonblock(socket_descriptor_t fd)
#define CC_DIGIT
digit isdigit()
Wrapper structure for dynamically allocated memory.
void dco_create_socket(HANDLE handle, struct addrinfo *remoteaddr, bool bind_local, struct addrinfo *bind, int timeout, struct signal_info *sig_info)
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
static bool streqnull(const char *a, const char *b)
static bool addr_defined_ipi(const struct link_socket_actual *lsa)
#define LS_MODE_TCP_LISTEN
const char * print_sockaddr_ex(const struct sockaddr *sa, const char *separator, const unsigned int flags, struct gc_arena *gc)
static int socket_defined(const socket_descriptor_t sd)
static void socket_set_sndbuf(socket_descriptor_t sd, int size)
struct link_socket_info info
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
struct link_socket_actual actual
bool link_socket_update_flags(struct link_socket *ls, unsigned int sockflags)
struct socket_buffer_size socket_buffer_sizes
static int socket_get_last_error(const struct link_socket *sock)
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
int signal_reset(struct signal_info *si, int signum)
Clear the signal if its current value equals signum.
struct link_socket * link_socket
void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
struct connection_entry ** array
struct http_proxy_info * http_proxy
struct http_proxy_info * http_proxy
Garbage collection arena used to keep track of dynamically allocated memory.
struct overlapped_io writes
void alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame)
#define GETADDR_MSG_VIRT_OUT
void close_net_event_win32(struct rw_handle *event, socket_descriptor_t sd, unsigned int flags)
struct signal_info * sig
Internal error signaling object.
bool string_class(const char *str, const unsigned int inclusive, const unsigned int exclusive)
void setenv_str(struct env_set *es, const char *name, const char *value)
static void SocketHandleSetInvalError(sockethandle_t sh)
#define ENABLE_IP_PKTINFO
int resolve_retry_seconds
int offset
Offset in bytes of the actual content within the allocated memory.
static void stream_buf_set_next(struct stream_buf *sb)
struct http_proxy_options * http_proxy_options
const char * print_in_port_t(in_port_t port, struct gc_arena *gc)
static void strncpynt(char *dest, const char *src, size_t maxlen)
event_t socket_listen_event_handle(struct link_socket *s)
void setenv_in6_addr(struct env_set *es, const char *name_prefix, const struct in6_addr *addr, const unsigned int flags)
static void stream_buf_init(struct stream_buf *sb, struct buffer *buf, const unsigned int sockflags, const int proto)
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
static void tcp_connection_established(const struct link_socket_actual *act)
const char * proxy_dest_port
bool buf_puts(struct buffer *buf, const char *str)
struct link_socket_actual socks_relay
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
void free_buf(struct buffer *buf)
SOCKET socket_descriptor_t
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
void bad_address_length(int actual, int expected)
void set_cloexec(socket_descriptor_t fd)
#define GETADDR_HOST_ORDER
void link_socket_init_phase1(struct context *c, int mode)
bool connection_established
struct rw_handle rw_handle
sa_family_t ascii2af(const char *proto_name)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
uint16_t packet_size_type
void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af)
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
void overlapped_io_init(struct overlapped_io *o, const struct frame *frame, BOOL event_state)
static bool stream_buf_read_setup(struct link_socket *sock)
static SERVICE_STATUS status
const char * display_form
static void create_socket(struct link_socket *sock, struct addrinfo *addr)
const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *gc)
static void gc_free(struct gc_arena *a)
static void gc_freeaddrinfo_callback(void *addr)
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
struct connection_list * connection_list
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
#define ALLOC_OBJ_CLEAR(dptr, type)
struct link_socket * link_socket_new(void)
#define GETADDR_CACHE_MASK
#define OPENVPN_STATE_RESOLVE
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
static void phase2_set_socket_flags(struct link_socket *sock)
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
#define openvpn_close_socket(s)
#define OPENVPN_PLUGIN_FUNC_SUCCESS
void do_preresolve(struct context *c)
static bool socket_set_tcp_nodelay(socket_descriptor_t sd, int state)
struct buffer stream_buf_data
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
static void socket_do_listen(socket_descriptor_t sd, const struct addrinfo *local, bool do_listen, bool do_set_nonblock)
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
#define IA_EMPTY_IF_UNDEF
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
void link_socket_update_buffer_sizes(struct link_socket *ls, int rcvbuf, int sndbuf)
struct event_timeout server_poll_interval
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
struct stream_buf stream_buf
bool plugin_defined(const struct plugin_list *pl, const int type)
static void socket_set_mark(socket_descriptor_t sd, int mark)
void setenv_link_socket_actual(struct env_set *es, const char *name_prefix, const struct link_socket_actual *act, const unsigned int flags)
#define SF_HOST_RANDOMIZE
static int buf_forward_capacity(const struct buffer *buf)
struct openvpn_sockaddr dest
#define SF_USE_IP_PKTINFO
socket_descriptor_t create_socket_tcp(struct addrinfo *addrinfo)
const char * ipchange_command
void register_signal(struct signal_info *si, int signum, const char *signal_text)
Register a soft signal in the signal_info struct si respecting priority.
static bool addr_local(const struct sockaddr *addr)
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int ai_family, const char *prefix, bool ipv6only)
struct buffer alloc_buf(size_t size)
static int af_addr_size(sa_family_t af)
struct in6_addr add_in6_addr(struct in6_addr base, uint32_t add)
static void phase2_socks_client(struct link_socket *sock, struct signal_info *sig_info)
#define PS_SHOW_PORT_IF_DEFINED
#define IPV4_INVALID_ADDR
int link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
const struct plugin_list * plugins
struct signal_info siginfo_static
struct cached_dns_entry * dns_cache
void link_socket_init_phase2(struct context *c)
const char * socket_stat(const struct link_socket *s, unsigned int rwflags, struct gc_arena *gc)
static void stream_buf_reset(struct stream_buf *sb)
struct socks_proxy_info * socks_proxy
static bool buf_defined(const struct buffer *buf)
void link_socket_close(struct link_socket *sock)
static bool dns_addr_safe(const char *addr)
bool buf_printf(struct buffer *buf, const char *format,...)
static socket_descriptor_t socket_listen_accept(socket_descriptor_t sd, struct link_socket_actual *act, const char *remote_dynamic, const struct addrinfo *local, bool do_listen, bool nowait, volatile int *signal_received)
void setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr_t addr, const unsigned int flags)
struct cached_dns_entry * dns_cache
static int socket_get_sndbuf(socket_descriptor_t sd)
const char * hostname_randomize(const char *hostname, struct gc_arena *gc)
struct addrinfo * remote_list
struct context_1 c1
Level 1 context.
static void create_socket_dco_win(struct context *c, struct link_socket *sock, struct signal_info *sig_info)
struct man_connection connection