26 #elif defined(_MSC_VER) 62 sf2gaf(
const unsigned int getaddr_flags,
63 const unsigned int sockflags)
80 void *network,
unsigned int *netbits,
84 char *endp, *sep, *var_host = NULL;
85 struct addrinfo *ai = NULL;
106 max_bits =
sizeof(
struct in6_addr) * 8;
111 "Unsupported AF family passed to getaddrinfo for %s (%d)",
121 var_host = strdup(hostname);
125 "Can't allocate hostname buffer for getaddrinfo");
130 sep = strchr(var_host,
'/');
133 bits = strtoul(sep + 1, &endp, 10);
134 if ((*endp !=
'\0') || (bits > max_bits))
136 msg(msglevel,
"IP prefix '%s': invalid '/bits' spec (%s)", hostname,
144 resolve_retry_seconds, signal_received, af, &ai);
145 if ((ret == 0) && network)
147 struct in6_addr *ip6;
154 *ip4 = ((
struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr;
164 *ip6 = ((
struct sockaddr_in6 *)ai->ai_addr)->sin6_addr;
170 "Unsupported AF family for %s (%d)", var_host, af);
194 const char *hostname,
195 int resolve_retry_seconds,
197 volatile int *signal_received)
203 resolve_retry_seconds, signal_received,
225 unsigned int *netbits,
int msglevel)
228 0, NULL, msglevel) < 0)
239 if (a == NULL && b == NULL)
243 else if (a == NULL || b == NULL)
259 const char *hostname,
260 const char *servname,
263 struct addrinfo **ai)
271 for (ph = dns_cache; ph; ph = ph->
next)
276 && ph->
flags == flags)
351 for (i = 0; i < l->
len; ++i)
355 int flags = preresolve_flags;
443 const char *hostname,
444 const char *servname,
445 int resolve_retry_seconds,
446 volatile int *signal_received,
448 struct addrinfo **res)
450 struct addrinfo hints;
455 const char *print_hostname;
456 const char *print_servname;
460 ASSERT(hostname || servname);
465 print_servname = servname;
480 signal_received = &sigrec;
485 hints.ai_family = ai_family;
486 hints.ai_flags = AI_NUMERICHOST;
490 hints.ai_flags |= AI_PASSIVE;
495 hints.ai_socktype = SOCK_DGRAM;
499 hints.ai_socktype = SOCK_STREAM;
502 status = getaddrinfo(hostname, servname, &hints, res);
506 const int fail_wait_interval = 5;
509 ((resolve_retry_seconds + 4)/ fail_wait_interval);
520 print_hostname = hostname;
524 print_hostname =
"undefined";
527 fmt =
"RESOLVE: Cannot resolve host address: %s:%s (%s)";
529 && !resolve_retry_seconds)
531 fmt =
"RESOLVE: Cannot resolve host address: %s:%s (%s) " 532 "(I would have retried this name query if you had " 533 "specified the --resolv-retry option.)";
538 msg(msglevel,
"RESOLVE: Cannot parse IP address: %s:%s (%s)",
539 print_hostname,print_servname, gai_strerror(status));
543 #ifdef ENABLE_MANAGEMENT 569 hints.ai_flags &= ~AI_NUMERICHOST;
571 "GETADDRINFO flags=0x%04x ai_family=%d ai_socktype=%d",
572 flags, hints.ai_family, hints.ai_socktype);
573 status = getaddrinfo(hostname, servname, &hints, res);
578 if (*signal_received)
580 if (*signal_received ==
SIGUSR1)
583 "RESOLVE: Ignored SIGUSR1 signal received during " 584 "DNS resolution attempt");
585 *signal_received = 0;
612 if (resolve_retries > 0)
621 gai_strerror(status));
623 if (--resolve_retries <= 0)
646 "WARNING: ignoring --remote-random-hostname because the " 647 "hostname is an IP address");
652 if (signal_received && *signal_received)
663 msg(level,
"RESOLVE: signal received during DNS resolution attempt");
677 unsigned int a, b, c, d;
680 if (sscanf(dotted_quad,
"%u.%u.%u.%u", &a, &b, &c, &d) == 4)
682 if (a < 256 && b < 256 && c < 256 && d < 256)
684 addr->s_addr = htonl(a<<24 | b<<16 | c<<8 | d);
708 if (strlen(dotted_quad) > 15)
717 const char *p = dotted_quad;
722 if (c >=
'0' && c <=
'9')
758 if (strlen(ipv6_text_addr) > INET6_ADDRSTRLEN)
766 return inet_pton( AF_INET6, ipv6_text_addr, &a6 ) == 1;
775 const size_t len = strlen(addr);
811 if (strlen(mac_addr) > 17)
820 const char *p = mac_addr;
825 if ( (c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f') || (c >=
'A' && c <=
'F') )
851 #if defined(HAVE_GETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_SNDBUF) 856 if (getsockopt(sd, SOL_SOCKET, SO_SNDBUF, (
void *) &val, &len) == 0
857 && len ==
sizeof(val))
868 #if defined(HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_SNDBUF) 869 if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (
void *) &size,
sizeof(size)) != 0)
871 msg(
M_WARN,
"NOTE: setsockopt SO_SNDBUF=%d failed", size);
879 #if defined(HAVE_GETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_RCVBUF) 884 if (getsockopt(sd, SOL_SOCKET, SO_RCVBUF, (
void *) &val, &len) == 0
885 && len ==
sizeof(val))
896 #if defined(HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_RCVBUF) 897 if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (
void *) &size,
sizeof(size)) != 0)
899 msg(
M_WARN,
"NOTE: setsockopt SO_RCVBUF=%d failed", size);
924 msg(
D_OSBUF,
"Socket Buffers: R=[%d->%d] S=[%d->%d]",
939 #if defined(_WIN32) || (defined(HAVE_SETSOCKOPT) && defined(IPPROTO_TCP) && defined(TCP_NODELAY)) 940 if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (
void *) &state,
sizeof(state)) != 0)
942 msg(
M_WARN,
"NOTE: setsockopt TCP_NODELAY=%d failed", state);
947 dmsg(
D_OSBUF,
"Socket flags: TCP_NODELAY=%d succeeded", state);
951 msg(
M_WARN,
"NOTE: setsockopt TCP_NODELAY=%d failed (No kernel support)", state);
959 #if defined(TARGET_LINUX) && HAVE_DECL_SO_MARK 960 if (mark && setsockopt(sd, SOL_SOCKET, SO_MARK, (
void *) &mark,
sizeof(mark)) != 0)
962 msg(
M_WARN,
"NOTE: setsockopt SO_MARK=%d failed", mark);
1015 ASSERT(addrinfo->ai_socktype == SOCK_STREAM);
1017 if ((sd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)
1019 msg(
M_ERR,
"Cannot create TCP socket");
1026 if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR,
1027 (
void *) &on,
sizeof(on)) < 0)
1029 msg(
M_ERR,
"TCP: Cannot setsockopt SO_REUSEADDR on TCP socket");
1047 ASSERT(addrinfo->ai_socktype == SOCK_DGRAM);
1049 if ((sd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)
1051 msg(
M_ERR,
"UDP: Cannot create UDP/UDP6 socket");
1053 #if ENABLE_IP_PKTINFO 1057 if (addrinfo->ai_family == AF_INET)
1059 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) 1060 if (setsockopt(sd,
SOL_IP, IP_PKTINFO,
1061 (
void *)&pad,
sizeof(pad)) < 0)
1063 msg(
M_ERR,
"UDP: failed setsockopt for IP_PKTINFO");
1065 #elif defined(IP_RECVDSTADDR) 1066 if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR,
1067 (
void *)&pad,
sizeof(pad)) < 0)
1069 msg(
M_ERR,
"UDP: failed setsockopt for IP_RECVDSTADDR");
1072 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h) 1075 else if (addrinfo->ai_family == AF_INET6)
1077 #ifndef IPV6_RECVPKTINFO 1078 if (setsockopt(sd, IPPROTO_IPV6, IPV6_PKTINFO,
1079 (
void *)&pad,
sizeof(pad)) < 0)
1081 if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
1082 (
void *)&pad,
sizeof(pad)) < 0)
1084 {
msg(
M_ERR,
"UDP: failed setsockopt for IPV6_RECVPKTINFO");}
1105 ai_family,
"SOCKS",
false);
1119 if (addr->ai_protocol == IPPROTO_UDP || addr->ai_socktype == SOCK_DGRAM)
1131 struct addrinfo addrinfo_tmp = *addr;
1132 addrinfo_tmp.ai_socktype = SOCK_STREAM;
1133 addrinfo_tmp.ai_protocol = IPPROTO_TCP;
1137 else if (addr->ai_protocol == IPPROTO_TCP || addr->ai_socktype == SOCK_STREAM)
1151 #if defined(TARGET_LINUX) 1155 if (setsockopt(sock->
sd, SOL_SOCKET, SO_BINDTODEVICE, sock->
bind_dev, strlen(sock->
bind_dev) + 1) != 0)
1166 #ifdef TARGET_ANDROID 1168 protect_fd_nonlocal(
int fd,
const struct sockaddr *addr)
1181 management_android_control(
management,
"PROTECTFD", __func__);
1190 const struct addrinfo *local,
1192 bool do_set_nonblock)
1198 msg(
M_INFO,
"Listening for incoming TCP connection on %s",
1202 msg(
M_ERR,
"TCP: listen() failed");
1207 if (do_set_nonblock)
1225 socklen_t remote_len =
sizeof(act->
dest.
addr);
1230 #ifdef HAVE_GETPEERNAME 1233 new_sd = getpeername(sd, &act->
dest.
addr.
sa, &remote_len);
1247 msg(
M_WARN,
"TCP: this OS does not provide the getpeername() function");
1252 new_sd = accept(sd, &act->
dest.
addr.
sa, &remote_len);
1271 else if (remote_len_af && remote_len != remote_len_af)
1273 msg(
D_LINK_ERRORS,
"TCP: Received strange incoming connection with unknown address length=%d", remote_len);
1290 msg(
M_INFO,
"TCP connection established with %s",
1298 const char *remote_dynamic,
1299 const struct addrinfo *local,
1302 volatile int *signal_received)
1323 status = select(sd + 1, &reads, NULL, NULL, &tv);
1326 if (*signal_received)
1347 struct addrinfo *ai = NULL;
1351 remote_verify.
addr.
sa.sa_family, &ai);
1357 "TCP NOTE: Rejected connection attempt from %s due to --remote setting",
1361 msg(
M_ERR,
"TCP: close socket failed (new_sd)");
1379 msg(
M_ERR,
"TCP: close socket failed (sd)");
1393 #define IPV6_V6ONLY 27 1398 struct addrinfo *local,
1412 struct addrinfo *cur;
1418 for (cur = local; cur; cur = cur->ai_next)
1420 if (cur->ai_family == ai_family)
1427 msg(
M_FATAL,
"%s: Socket bind failed: Addr to bind has no %s record",
1431 if (ai_family == AF_INET6)
1433 int v6only = ipv6only ? 1 : 0;
1435 msg(
M_INFO,
"setsockopt(IPV6_V6ONLY=%d)", v6only);
1436 if (setsockopt(sd, IPPROTO_IPV6,
IPV6_V6ONLY, (
void *) &v6only,
sizeof(v6only)))
1441 if (bind(sd, cur->ai_addr, cur->ai_addrlen))
1452 const struct sockaddr *remote,
1453 int connect_timeout,
1454 volatile int *signal_received)
1458 #ifdef TARGET_ANDROID 1459 protect_fd_nonlocal(sd, remote);
1462 #ifdef CONNECT_NONBLOCK 1464 status = connect(sd, remote,
af_addr_size(remote->sa_family));
1471 status == WSAEWOULDBLOCK
1473 status == EINPROGRESS
1480 struct pollfd fds[1];
1482 fds[0].events = POLLOUT;
1483 status = poll(fds, 1, (connect_timeout > 0) ? 1000 : 0);
1490 tv.tv_sec = (connect_timeout > 0) ? 1 : 0;
1493 status = select(sd + 1, NULL, &writes, NULL, &tv);
1495 if (signal_received)
1498 if (*signal_received)
1511 if (--connect_timeout < 0)
1514 status = WSAETIMEDOUT;
1530 if (getsockopt(sd, SOL_SOCKET, SO_ERROR, (
void *) &val, &len) == 0
1531 && len ==
sizeof(val))
1544 status = connect(sd, remote,
af_addr_size(remote->sa_family));
1560 if (ai->ai_family == AF_INET)
1563 *((
struct sockaddr_in *) ai->ai_addr);
1565 else if (ai->ai_family == AF_INET6)
1568 *((
struct sockaddr_in6 *) ai->ai_addr);
1579 const struct sockaddr *
dest,
1580 const int connect_timeout,
1586 #ifdef CONNECT_NONBLOCK 1587 msg(
M_INFO,
"Attempting to establish TCP connection with %s [nonblock]",
1590 msg(
M_INFO,
"Attempting to establish TCP connection with %s",
1594 #ifdef ENABLE_MANAGEMENT 1629 msg(
M_INFO,
"TCP connection established with %s",
1645 const unsigned int sockflags,
const int proto);
1730 msg(
M_FATAL,
"getaddrinfo() failed for local \"%s:%s\": %s",
1732 gai_strerror(status));
1742 const char **remote_dynamic,
1743 volatile int *signal_received)
1755 struct addrinfo *ai;
1769 else if (phase == 1)
1781 else if (phase == 2)
1807 retry, signal_received, sock->
info.
af, &ai);
1816 "RESOLVE_REMOTE flags=0x%04x phase=%d rrs=%d sig=%d status=%d",
1820 signal_received ? *signal_received : -1,
1823 if (signal_received)
1825 if (*signal_received)
1832 if (signal_received)
1844 msg(
M_INFO,
"TCP/UDP: Preserving recently used remote address: %s",
1848 *remote_dynamic = NULL;
1887 bool bind_ipv6_only,
1899 const char *ipchange_command,
1925 sock->gremlin = gremlin;
1950 sock->
sd = accept_from->
sd;
2022 const char *remote_dynamic,
volatile int *signal_received)
2024 bool remote_changed =
false;
2030 #ifdef HAVE_GETSOCKNAME 2034 socklen_t addrlen =
sizeof(local_addr);
2035 if (getsockname(sock->
sd, &local_addr.
addr.
sa, &addrlen) == 0)
2040 local_addr.
addr.
sa.sa_family, (
int)sock->
sd);
2044 int saved_errno = errno;
2048 if (saved_errno == ENOTSOCK)
2050 msg(
M_FATAL,
"ERROR: socket required for --inetd operation");
2055 msg(
M_WARN,
"inetd(%s): this OS does not provide the getsockname() " 2056 "function, using AF_INET",
2083 #if EXTENDED_SOCKET_ERROR_CAPABILITY 2085 set_sock_extended_error_passing(sock->
sd);
2107 struct addrinfo *cur;
2110 if (!ai_family || ai_family == cur->ai_family)
2116 msg(msglevel,
"%s link local (bound): %s",
2122 msg(msglevel,
"%s link local: (not bound)",
2127 msg(msglevel,
"%s link remote: %s",
2138 volatile int *signal_received)
2180 bool proxy_retry =
false;
2217 }
while (proxy_retry);
2265 const char *remote_dynamic = NULL;
2321 if (sock->
info.
af == AF_UNSPEC)
2323 msg(
M_WARN,
"Could not determine IPv4/IPv6 protocol. Using %s",
2335 msg(
M_WARN,
"Could not determine IPv4/IPv6 protocol");
2359 #ifdef TARGET_ANDROID 2390 const int gremlin = GREMLIN_CONNECTION_FLOOD_LEVEL(sock->gremlin);
2392 const int gremlin = 0;
2402 msg(
D_LOW,
"TCP/UDP: Closing socket");
2471 const char *common_name,
2501 msg(
M_WARN,
"WARNING: ipchange plugin call failed");
2525 struct addrinfo *ai;
2532 "TCP/UDP: Incoming packet rejected from %s[%d], expected peer address: %s (allow this incoming source address/port by removing --remote or adding --float)",
2580 return ntohl(((
struct sockaddr_in *)lsa->
current_remote->ai_addr)
2589 const struct in6_addr *
2611 return &(((
struct sockaddr_in6 *)lsa->
current_remote->ai_addr)->sin6_addr);
2672 const unsigned int sockflags,
2748 if (length_added > 0)
2750 sb->
buf.
len += length_added;
2760 if (sb->port_share_state == PS_ENABLED)
2762 if (!is_openvpn_protocol(&sb->
buf))
2765 sb->port_share_state = PS_FOREIGN;
2771 sb->port_share_state = PS_DISABLED;
2781 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);
2841 const char *separator,
2842 const unsigned int flags,
2846 bool addr_is_defined =
false;
2847 char hostaddr[NI_MAXHOST] =
"";
2848 char servname[NI_MAXSERV] =
"";
2851 socklen_t salen = 0;
2852 switch (sa->sa_family)
2859 salen =
sizeof(
struct sockaddr_in);
2860 addr_is_defined = ((
struct sockaddr_in *) sa)->sin_addr.s_addr != 0;
2864 if (!(flags & PS_DONT_SHOW_FAMILY))
2868 salen =
sizeof(
struct sockaddr_in6);
2869 addr_is_defined = !IN6_IS_ADDR_UNSPECIFIED(&((
struct sockaddr_in6 *) sa)->sin6_addr);
2873 if (!(flags & PS_DONT_SHOW_FAMILY))
2875 return "[AF_UNSPEC]";
2886 status = getnameinfo(sa, salen, hostaddr,
sizeof(hostaddr),
2887 servname,
sizeof(servname), NI_NUMERICHOST | NI_NUMERICSERV);
2891 buf_printf(&out,
"[nameinfo() err: %s]",gai_strerror(status));
2897 if (addr_is_defined)
2927 #define IF_NAMESIZE 16 2932 const char *separator,
2933 const unsigned int flags,
2941 #if ENABLE_IP_PKTINFO 2950 sa.
addr.
in4.sin_family = AF_INET;
2951 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) 2952 sa.
addr.
in4.sin_addr = act->pi.in4.ipi_spec_dst;
2953 if_indextoname(act->pi.in4.ipi_ifindex, ifname);
2954 #elif defined(IP_RECVDSTADDR) 2955 sa.
addr.
in4.sin_addr = act->pi.in4;
2958 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h) 2968 struct sockaddr_in6 sin6;
2969 char buf[INET6_ADDRSTRLEN] =
"[undef]";
2971 sin6.sin6_family = AF_INET6;
2972 sin6.sin6_addr = act->pi.in6.ipi6_addr;
2973 if_indextoname(act->pi.in6.ipi6_ifindex, ifname);
2974 if (getnameinfo((
struct sockaddr *)&sin6,
sizeof(
struct sockaddr_in6),
2975 buf,
sizeof(buf), NULL, 0, NI_NUMERICHOST) == 0)
2977 buf_printf(&out,
" (via %s%%%s)", buf, ifname);
2981 buf_printf(&out,
" (via [getnameinfo() err]%%%s)", ifname);
3009 ia.s_addr = (flags &
IA_NET_ORDER) ? addr : htonl(addr);
3024 char tmp_out_buf[64];
3026 if (memcmp(&a6, &in6addr_any,
sizeof(a6)) != 0
3029 inet_ntop(AF_INET6, &a6, tmp_out_buf,
sizeof(tmp_out_buf)-1);
3036 #define UINT8_MAX 0xff 3047 for (i = 15; i>=0 &&
add > 0; i--)
3052 h = (
unsigned char) base.s6_addr[i];
3058 carry = ((h & 0xff) + (
add & 0xff)) >> 8;
3071 switch (addr->
addr.
sa.sa_family)
3085 if ((flags & SA_IP_PORT) && addr->
addr.
in4.sin_port)
3093 if (IN6_IS_ADDR_V4MAPPED( &addr->
addr.
in6.sin6_addr ))
3096 memcpy(&ia.s_addr, &addr->
addr.
in6.sin6_addr.s6_addr[12],
3104 getnameinfo(&addr->
addr.
sa,
sizeof(
struct sockaddr_in6),
3105 buf,
sizeof(buf), NULL, 0, NI_NUMERICHOST);
3109 if ((flags & SA_IP_PORT) && addr->
addr.
in6.sin6_port)
3125 si.
addr.
in4.sin_family = AF_INET;
3126 si.
addr.
in4.sin_addr.s_addr = htonl(addr);
3133 const char *name_prefix,
3134 const struct in6_addr *
addr,
3135 const unsigned int flags)
3141 si.
addr.
in6.sin6_family = AF_INET6;
3149 const char *name_prefix,
3151 const unsigned int flags)
3169 {
"proto-uninitialized",
"proto-NONE", AF_UNSPEC,
PROTO_NONE},
3176 {
"udp4",
"UDPv4", AF_INET, PROTO_UDP},
3177 {
"tcp4-server",
"TCPv4_SERVER", AF_INET, PROTO_TCP_SERVER},
3178 {
"tcp4-client",
"TCPv4_CLIENT", AF_INET, PROTO_TCP_CLIENT},
3179 {
"tcp4",
"TCPv4", AF_INET, PROTO_TCP},
3181 {
"udp6",
"UDPv6", AF_INET6, PROTO_UDP},
3182 {
"tcp6-server",
"TCPv6_SERVER", AF_INET6, PROTO_TCP_SERVER},
3183 {
"tcp6-client",
"TCPv6_CLIENT", AF_INET6, PROTO_TCP_CLIENT},
3184 {
"tcp6",
"TCPv6", AF_INET6, PROTO_TCP},
3190 if (proto < 0 || proto >=
PROTO_N)
3206 if (proto < 0 || proto >=
PROTO_N)
3216 if (proto < 0 || proto >=
PROTO_N)
3227 for (i = 0; i <
SIZE(proto_names); ++i)
3229 if (!strcmp(proto_name, proto_names[i].
short_form))
3231 return proto_names[i].
proto;
3241 for (i = 0; i <
SIZE(proto_names); ++i)
3243 if (!strcmp(proto_name, proto_names[i].
short_form))
3255 for (i = 0; i <
SIZE(proto_names); ++i)
3257 if (proto_names[i].
proto_af == af && proto_names[i].proto == proto)
3270 return "[unknown protocol]";
3279 for (i = 0; i <
SIZE(proto_names); ++i)
3285 buf_printf(&out,
"[%s]", proto_names[i].short_form);
3295 case AF_INET:
return "AF_INET";
3297 case AF_INET6:
return "AF_INET6";
3326 return "TCPv4_SERVER";
3331 return "TCPv4_CLIENT";
3345 msg(
M_FATAL,
"ERROR: received strange incoming packet with an address length of %d -- we only accept address lengths of %d.",
3389 return buf->
len = 0;
3395 #if ENABLE_IP_PKTINFO 3400 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) 3401 #define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \ 3402 CMSG_SPACE(sizeof(struct in_pktinfo)) ) 3404 #define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \ 3405 CMSG_SPACE(sizeof(struct in_addr)) ) 3409 link_socket_read_udp_posix_recvmsg(
struct link_socket *sock,
3414 uint8_t pktinfo_buf[PKTINFO_BUF_SIZE];
3416 socklen_t fromlen =
sizeof(from->
dest.
addr);
3418 iov.iov_base =
BPTR(buf);
3420 mesg.msg_iov = &iov;
3421 mesg.msg_iovlen = 1;
3423 mesg.msg_namelen = fromlen;
3424 mesg.msg_control = pktinfo_buf;
3425 mesg.msg_controllen =
sizeof pktinfo_buf;
3426 buf->
len = recvmsg(sock->
sd, &mesg, 0);
3429 struct cmsghdr *cmsg;
3430 fromlen = mesg.msg_namelen;
3431 cmsg = CMSG_FIRSTHDR(&mesg);
3433 && CMSG_NXTHDR(&mesg, cmsg) == NULL
3435 && cmsg->cmsg_level ==
SOL_IP 3436 && cmsg->cmsg_type == IP_PKTINFO
3437 && cmsg->cmsg_len >= CMSG_LEN(
sizeof(
struct in_pktinfo)) )
3438 #elif defined(IP_RECVDSTADDR) 3439 && cmsg->cmsg_level == IPPROTO_IP
3440 && cmsg->cmsg_type == IP_RECVDSTADDR
3441 && cmsg->cmsg_len >= CMSG_LEN(
sizeof(
struct in_addr)) )
3443 #error
ENABLE_IP_PKTINFO is
set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
3446 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) 3447 struct in_pktinfo *pkti = (
struct in_pktinfo *) CMSG_DATA(cmsg);
3448 from->pi.in4.ipi_ifindex = pkti->ipi_ifindex;
3449 from->pi.in4.ipi_spec_dst = pkti->ipi_spec_dst;
3450 #elif defined(IP_RECVDSTADDR) 3451 from->pi.in4 = *(
struct in_addr *) CMSG_DATA(cmsg);
3453 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h) 3456 else if (cmsg != NULL
3457 && CMSG_NXTHDR(&mesg, cmsg) == NULL
3458 && cmsg->cmsg_level == IPPROTO_IPV6
3459 && cmsg->cmsg_type == IPV6_PKTINFO
3460 && cmsg->cmsg_len >= CMSG_LEN(
sizeof(
struct in6_pktinfo)) )
3462 struct in6_pktinfo *pkti6 = (
struct in6_pktinfo *) CMSG_DATA(cmsg);
3463 from->pi.in6.ipi6_ifindex = pkti6->ipi6_ifindex;
3464 from->pi.in6.ipi6_addr = pkti6->ipi6_addr;
3466 else if (cmsg != NULL)
3468 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 );
3477 link_socket_read_udp_posix(
struct link_socket *sock,
3481 socklen_t fromlen =
sizeof(from->
dest.
addr);
3484 #if ENABLE_IP_PKTINFO 3488 fromlen = link_socket_read_udp_posix_recvmsg(sock, buf, from);
3495 if (buf->
len >= 0 && expectedlen && fromlen != expectedlen)
3521 return link_socket_write_tcp_posix(sock, buf, to);
3525 #if ENABLE_IP_PKTINFO 3528 link_socket_write_udp_posix_sendmsg(
struct link_socket *sock,
3534 struct cmsghdr *cmsg;
3535 uint8_t pktinfo_buf[PKTINFO_BUF_SIZE];
3537 iov.iov_base =
BPTR(buf);
3538 iov.iov_len =
BLEN(buf);
3539 mesg.msg_iov = &iov;
3540 mesg.msg_iovlen = 1;
3546 mesg.msg_namelen =
sizeof(
struct sockaddr_in);
3547 mesg.msg_control = pktinfo_buf;
3549 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) 3550 mesg.msg_controllen = CMSG_SPACE(
sizeof(
struct in_pktinfo));
3551 cmsg = CMSG_FIRSTHDR(&mesg);
3552 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_pktinfo));
3553 cmsg->cmsg_level =
SOL_IP;
3554 cmsg->cmsg_type = IP_PKTINFO;
3556 struct in_pktinfo *pkti;
3557 pkti = (
struct in_pktinfo *) CMSG_DATA(cmsg);
3558 pkti->ipi_ifindex = to->pi.in4.ipi_ifindex;
3559 pkti->ipi_spec_dst = to->pi.in4.ipi_spec_dst;
3560 pkti->ipi_addr.s_addr = 0;
3562 #elif defined(IP_RECVDSTADDR) 3563 ASSERT( CMSG_SPACE(
sizeof(
struct in_addr)) <=
sizeof(pktinfo_buf) );
3564 mesg.msg_controllen = CMSG_SPACE(
sizeof(
struct in_addr));
3565 cmsg = CMSG_FIRSTHDR(&mesg);
3566 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_addr));
3567 cmsg->cmsg_level = IPPROTO_IP;
3568 cmsg->cmsg_type = IP_RECVDSTADDR;
3569 *(
struct in_addr *) CMSG_DATA(cmsg) = to->pi.in4;
3571 #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h) 3578 struct in6_pktinfo *pkti6;
3580 mesg.msg_namelen =
sizeof(
struct sockaddr_in6);
3582 ASSERT( CMSG_SPACE(
sizeof(
struct in6_pktinfo)) <=
sizeof(pktinfo_buf) );
3583 mesg.msg_control = pktinfo_buf;
3584 mesg.msg_controllen = CMSG_SPACE(
sizeof(
struct in6_pktinfo));
3586 cmsg = CMSG_FIRSTHDR(&mesg);
3587 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in6_pktinfo));
3588 cmsg->cmsg_level = IPPROTO_IPV6;
3589 cmsg->cmsg_type = IPV6_PKTINFO;
3591 pkti6 = (
struct in6_pktinfo *) CMSG_DATA(cmsg);
3592 pkti6->ipi6_ifindex = to->pi.in6.ipi6_ifindex;
3593 pkti6->ipi6_addr = to->pi.in6.ipi6_addr;
3599 return sendmsg(sock->
sd, &mesg, 0);
3634 wsabuf[0].len = maxsize ? maxsize :
BLEN(&sock->
reads.
buf);
3647 status = WSARecvFrom(
3690 dmsg(
D_WIN32_IO,
"WIN32 I/O: Socket Receive immediate return [%d,%d]",
3691 (
int) wsabuf[0].len,
3696 status = WSAGetLastError();
3697 if (status == WSA_IO_PENDING)
3702 (
int) wsabuf[0].len);
3711 (
int) wsabuf[0].len,
3796 dmsg(
D_WIN32_IO,
"WIN32 I/O: Socket Send immediate return [%d,%d]",
3797 (
int) wsabuf[0].len,
3802 status = WSAGetLastError();
3803 if (status == WSA_IO_PENDING)
3808 (
int) wsabuf[0].len);
3818 (
int) wsabuf[0].len,
3840 status = WSAGetOverlappedResult(
3858 dmsg(
D_WIN32_IO,
"WIN32 I/O: Socket Completion success [%d]", ret);
3864 if (WSAGetLastError() != WSA_IO_INCOMPLETE)
3880 WSASetLastError(io->
status);
3892 dmsg(
D_WIN32_IO,
"WIN32 I/O: Socket Completion non-queued success [%d]", ret);
3897 WSASetLastError(WSAEINVAL);
3919 case sizeof(
struct sockaddr_in):
3920 case sizeof(struct sockaddr_in6):
3923 case sizeof(struct sockaddr_in6)-4:
3930 switch (io->addr.sin_family)
3963 unsigned int rwflags,
3965 unsigned int *persistent)
3972 rwflags &= ~EVENT_READ;
3976 if (rwflags & EVENT_READ)
3983 if (!persistent || *persistent != rwflags)
3988 *persistent = rwflags;
4007 #if UNIX_SOCK_SUPPORT 4014 sockaddr_unix_name(
const struct sockaddr_un *local,
const char *null)
4016 if (local && local->sun_family == PF_UNIX)
4018 return local->sun_path;
4027 create_socket_unix(
void)
4031 if ((sd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
4033 msg(
M_ERR,
"Cannot create unix domain socket");
4045 struct sockaddr_un *local,
4051 const mode_t orig_umask = umask(0);
4054 if (bind(sd, (
struct sockaddr *) local,
sizeof(
struct sockaddr_un)))
4057 "%s: Socket bind[%d] failed on unix domain socket %s",
4060 sockaddr_unix_name(local,
"NULL"));
4072 struct sockaddr_un *remote)
4074 socklen_t remote_len =
sizeof(
struct sockaddr_un);
4078 ret = accept(sd, (
struct sockaddr *) remote, &remote_len);
4090 struct sockaddr_un *remote)
4092 int status = connect(sd, (
struct sockaddr *) remote,
sizeof(
struct sockaddr_un));
4101 sockaddr_unix_init(
struct sockaddr_un *local,
const char *path)
4103 local->sun_family = PF_UNIX;
4104 strncpynt(local->sun_path, path,
sizeof(local->sun_path));
4108 socket_delete_unix(
const struct sockaddr_un *local)
4110 const char *name = sockaddr_unix_name(local, NULL);
4112 if (name && strlen(name))
4122 #ifdef HAVE_GETPEEREID 4125 if (getpeereid(sd, &u, &g) == -1)
4138 #elif defined(SO_PEERCRED) 4139 struct ucred peercred;
4140 socklen_t so_len =
sizeof(peercred);
4141 if (getsockopt(sd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1)
4147 *uid = peercred.uid;
4151 *gid = peercred.gid;
bool string_class(const char *str, const unsigned int inclusive, const unsigned int exclusive)
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
#define OPENVPN_STATE_RESOLVE
struct link_socket_actual socks_relay
#define PS_SHOW_PORT_IF_DEFINED
static void strncpynt(char *dest, const char *src, size_t maxlen)
const char * socks_proxy_port
static int socket_get_rcvbuf(int sd)
int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, volatile int *signal_received, int ai_family, struct addrinfo **res)
#define GETADDR_WARN_ON_SIGNAL
struct options options
Options loaded from command line or configuration file.
void free_buf(struct buffer *buf)
struct link_socket * link_socket_new(void)
void init_net_event_win32(struct rw_handle *event, long network_events, socket_descriptor_t sd, unsigned int flags)
struct sockaddr_in6 addr6
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
struct link_socket_addr * lsa
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
struct cached_dns_entry * dns_cache
void establish_socks_proxy_passthru(struct socks_proxy_info *p, socket_descriptor_t sd, const char *host, const char *servname, volatile int *signal_received)
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, volatile int *signal_received)
Translate an IPv4 addr or hostname from string form to in_addr_t.
sa_family_t ascii2af(const char *proto_name)
socket_descriptor_t ctrl_sd
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
Contains all state information for one tunnel.
Packet geometry parameters.
bool proto_is_tcp(int proto)
static bool streqnull(const char *a, const char *b)
struct http_proxy_info * http_proxy
void overlapped_io_init(struct overlapped_io *o, const struct frame *frame, BOOL event_state, bool tuntap_buffer)
#define IPv6_UDP_HEADER_SIZE
bool proto_is_udp(int proto)
static int af_addr_size(sa_family_t af)
void throw_signal_soft(const int signum, const char *signal_text)
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)
const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_arena *gc)
static void gc_free(struct gc_arena *a)
struct rw_handle listen_handle
bool proto_is_net(int proto)
static void frame_add_to_extra_frame(struct frame *frame, const unsigned int increment)
static int plugin_call(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es)
#define IPv6_TCP_HEADER_SIZE
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
static bool buf_safe(const struct buffer *buf, int len)
struct man_connection connection
unsigned short sa_family_t
#define SET_MTU_UPPER_BOUND
struct buffer alloc_buf(size_t size)
static void stream_buf_get_final(struct stream_buf *sb, struct buffer *buf)
struct connection_list * connection_list
int openvpn_inet_aton(const char *dotted_quad, struct in_addr *addr)
struct link_socket_actual actual
bool buf_printf(struct buffer *buf, const char *format,...)
void set_mtu_discover_type(int sd, int mtu_type, sa_family_t proto_af)
const char * proto2ascii_all(struct gc_arena *gc)
int resolve_retry_seconds
const int proto_overhead[]
void setenv_str(struct env_set *es, const char *name, const char *value)
#define SF_GETADDRINFO_DGRAM
#define OPENVPN_STATE_TCP_CONNECT
const char * hostname_randomize(const char *hostname, struct gc_arena *gc)
static void tcp_connection_established(const struct link_socket_actual *act)
struct cached_dns_entry * next
bool link_socket_update_flags(struct link_socket *ls, unsigned int sockflags)
struct link_socket_info info
static void get_signal(volatile int *sig)
const char * display_form
#define GETADDR_MENTION_RESOLVE_RETRY
#define OPENVPN_PLUGIN_FUNC_SUCCESS
const char * proxy_dest_host
static bool link_socket_connection_oriented(const struct link_socket *sock)
int ascii2proto(const char *proto_name)
#define GETADDR_RANDOMIZE
void close_net_event_win32(struct rw_handle *event, socket_descriptor_t sd, unsigned int flags)
const char * proto_remote(int proto, bool remote)
static bool buf_read(struct buffer *src, void *dest, int size)
static event_t socket_event_handle(const struct link_socket *s)
int offset
Offset in bytes of the actual content within the allocated memory.
static socket_descriptor_t create_socket_udp(struct addrinfo *addrinfo, const unsigned int flags)
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)
int len
Length in bytes of the actual content within the allocated memory.
const struct plugin_list * plugins
int inet_pton(int af, const char *src, void *dst)
static void phase2_tcp_client(struct link_socket *sock, struct signal_info *sig_info)
void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
#define openvpn_close_socket(s)
#define LS_MODE_TCP_ACCEPT_FROM
struct context_1 c1
Level 1 context.
static void bind_local(struct link_socket *sock, const sa_family_t ai_family)
#define OPENVPN_PLUGIN_IPCHANGE
struct socks_proxy_info * socks_proxy
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
#define IPV4_INVALID_ADDR
#define IPv4_UDP_HEADER_SIZE
struct stream_buf stream_buf
#define PS_DONT_SHOW_FAMILY
static void stream_buf_close(struct stream_buf *sb)
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
int socket_recv_queue(struct link_socket *sock, int maxsize)
int socket_finalize(SOCKET s, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
static void socket_connect(socket_descriptor_t *sd, const struct sockaddr *dest, const int connect_timeout, struct signal_info *sig_info)
struct socket_buffer_size socket_buffer_sizes
const char * socks_proxy_server
#define IA_EMPTY_IF_UNDEF
#define LS_MODE_TCP_LISTEN
#define GETADDR_UPDATE_MANAGEMENT_STATE
#define IPv4_TCP_HEADER_SIZE
void setenv_link_socket_actual(struct env_set *es, const char *name_prefix, const struct link_socket_actual *act, const unsigned int flags)
void gc_addspecial(void *addr, void(*free_function)(void *), struct gc_arena *a)
bool buf_puts(struct buffer *buf, const char *str)
const char * print_link_socket_actual_ex(const struct link_socket_actual *act, const char *separator, const unsigned int flags, struct gc_arena *gc)
int resolve_retry_seconds
bool ip_or_dns_addr_safe(const char *addr, const bool allow_fqdn)
static struct gc_arena gc_new(void)
#define IOSTATE_IMMEDIATE_RETURN
static void openvpn_fd_set(int fd, fd_set *setp)
struct addrinfo * bind_local
struct addrinfo * current_remote
static const char * print_sockaddr(const struct sockaddr *addr, struct gc_arena *gc)
int inetd_socket_descriptor
static bool addrlist_match(const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
void link_socket_bad_outgoing_addr(void)
static bool addr_defined_ipi(const struct link_socket_actual *lsa)
#define ALLOC_OBJ_CLEAR(dptr, type)
static void ipchange_fmt(const bool include_cmd, struct argv *argv, const struct link_socket_info *info, struct gc_arena *gc)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
int get_server_poll_remaining_time(struct event_timeout *server_poll_timeout)
const char * proxy_dest_port
static bool buf_copy_excess(struct buffer *dest, struct buffer *src, int len)
static void stream_buf_get_next(struct stream_buf *sb, struct buffer *buf)
unsigned __int32 uint32_t
static void gc_freeaddrinfo_callback(void *addr)
static int socket_defined(const socket_descriptor_t sd)
struct http_proxy_options * http_proxy_options
static bool link_socket_actual_defined(const struct link_socket_actual *act)
void setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct openvpn_sockaddr *addr, const unsigned int flags)
void overlapped_io_close(struct overlapped_io *o)
bool stream_buf_read_setup_dowork(struct link_socket *sock)
static bool defined_net_event_win32(const struct rw_handle *event)
static void linksock_print_addr(struct link_socket *sock)
static SERVICE_STATUS status
static int buf_forward_capacity(const struct buffer *buf)
void link_socket_init_phase1(struct link_socket *sock, const char *local_host, const char *local_port, const char *remote_host, const char *remote_port, struct cached_dns_entry *dns_cache, int proto, sa_family_t af, bool bind_ipv6_only, int mode, const struct link_socket *accept_from, struct http_proxy_info *http_proxy, struct socks_proxy_info *socks_proxy, bool bind_local, bool remote_float, int inetd, struct link_socket_addr *lsa, const char *ipchange_command, const struct plugin_list *plugins, int resolve_retry_seconds, int mtu_discover_type, int rcvbuf, int sndbuf, int mark, const char *bind_dev, struct event_timeout *server_poll_timeout, unsigned int sockflags)
static bool socket_set_rcvbuf(int sd, int size)
int link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
void link_socket_init_phase2(struct link_socket *sock, const struct frame *frame, struct signal_info *sig_info)
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int ai_family, const char *prefix, bool ipv6only)
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
union openvpn_sockaddr::@10 addr
void sd_close(socket_descriptor_t *sd)
struct addrinfo * remote_list
static bool buf_copy(struct buffer *dest, const struct buffer *src)
const char * socket_stat(const struct link_socket *s, unsigned int rwflags, struct gc_arena *gc)
static bool stream_buf_added(struct stream_buf *sb, int length_added)
static void resolve_remote(struct link_socket *sock, int phase, const char **remote_dynamic, volatile int *signal_received)
#define HAVE_IPI_SPEC_DST
Interface functions to the internal and external multiplexers.
static void phase2_set_socket_flags(struct link_socket *sock)
#define GETADDR_HOST_ORDER
static void stream_buf_reset(struct stream_buf *sb)
static void phase2_inetd(struct link_socket *sock, const struct frame *frame, const char *remote_dynamic, volatile int *signal_received)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
struct overlapped_io writes
char * overlapped_io_state_ascii(const struct overlapped_io *o)
static void socket_set_mark(int sd, int mark)
static bool stream_buf_read_setup(struct link_socket *sock)
static bool socket_set_flags(int sd, unsigned int sockflags)
#define FRAME_HEADROOM_MARKER_READ_STREAM
static void socket_frame_init(const struct frame *frame, struct link_socket *sock)
void alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame, const bool tuntap_buffer, const unsigned int align_mask)
#define SA_SET_IF_NONZERO
struct connection_entry * array[CONNECTION_LIST_SIZE]
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
static bool buf_defined(const struct buffer *buf)
const char * ip_remote_hint
#define SIG_SOURCE_CONNECTION_FAILED
const char * print_sockaddr_ex(const struct sockaddr *sa, const char *separator, const unsigned int flags, struct gc_arena *gc)
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
void setenv_in6_addr(struct env_set *es, const char *name_prefix, const struct in6_addr *addr, const unsigned int flags)
void frame_set_mtu_dynamic(struct frame *frame, int mtu, unsigned int flags)
volatile int signal_received
struct rw_handle rw_handle
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
uint16_t packet_size_type
bool plugin_defined(const struct plugin_list *pl, const int type)
socket_descriptor_t create_socket_tcp(struct addrinfo *addrinfo)
bool ip_addr_dotted_quad_safe(const char *dotted_quad)
void bad_address_length(int actual, int expected)
void socket_adjust_frame_parameters(struct frame *frame, int proto)
SOCKET socket_descriptor_t
static void socket_set_buffers(int fd, const struct socket_buffer_size *sbs)
static void phase2_socks_client(struct link_socket *sock, struct signal_info *sig_info)
void setenv_int(struct env_set *es, const char *name, int value)
Wrapper structure for dynamically allocated memory.
bool connection_established
static void socket_do_listen(socket_descriptor_t sd, const struct addrinfo *local, bool do_listen, bool do_set_nonblock)
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
void set_nonblock(int fd)
bool proto_is_dgram(int proto)
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
void frame_adjust_path_mtu(struct frame *frame, int pmtu, int proto)
#define GETADDR_CACHE_MASK
#define buf_init(buf, offset)
bool residual_fully_formed
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
static bool socket_set_tcp_nodelay(int sd, int state)
static unsigned int sf2gaf(const unsigned int getaddr_flags, const unsigned int sockflags)
void do_preresolve(struct context *c)
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 phase2_tcp_server(struct link_socket *sock, const char *remote_dynamic, volatile int *signal_received)
static void resolve_bind_local(struct link_socket *sock, const sa_family_t af)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
struct cached_dns_entry * dns_cache
#define ENABLE_IP_PKTINFO
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, volatile int *signal_received)
#define GETADDR_MSG_VIRT_OUT
static bool dns_addr_safe(const char *addr)
static int get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, void *network, unsigned int *netbits, int resolve_retry_seconds, volatile int *signal_received, int msglevel)
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
static void addr_zero_host(struct openvpn_sockaddr *addr)
static void create_socket(struct link_socket *sock, struct addrinfo *addr)
static int buf_forward_capacity_total(const struct buffer *buf)
static int do_preresolve_host(struct context *c, const char *hostname, const char *servname, const int af, const int flags)
static void buf_reset(struct buffer *buf)
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...
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.
Garbage collection arena used to keep track of dynamically allocated memory.
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, volatile int *signal_received)
void management_sleep(const int n)
A sleep function that services the management layer for n seconds rather than doing nothing...
#define GETADDR_FATAL_ON_SIGNAL
void link_socket_update_buffer_sizes(struct link_socket *ls, int rcvbuf, int sndbuf)
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
#define PS_DONT_SHOW_ADDR
struct gc_arena gc
Garbage collection arena for allocations done in the scope of this context structure.
static bool addr_local(const struct sockaddr *addr)
void link_socket_close(struct link_socket *sock)
event_t socket_listen_event_handle(struct link_socket *s)
int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
static int datagram_overhead(int proto)
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
struct event_timeout * server_poll_timeout
void setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr_t addr, const unsigned int flags)
struct overlapped_io reads
bool mac_addr_safe(const char *mac_addr)
static void stream_buf_set_next(struct stream_buf *sb)
unsigned int rwflags_debug
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 SF_USE_IP_PKTINFO
const char * ipchange_command
static void socket_set_sndbuf(int sd, int size)
static void stream_buf_init(struct stream_buf *sb, struct buffer *buf, const unsigned int sockflags, const int proto)
static bool openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook)
struct buffer stream_buf_data
#define SF_HOST_RANDOMIZE
#define RESOLV_RETRY_INFINITE
struct http_proxy_options options
static bool link_socket_proto_connection_oriented(int proto)
bool ipv6_addr_safe(const char *ipv6_text_addr)
struct openvpn_sockaddr dest
struct in6_addr add_in6_addr(struct in6_addr base, uint32_t add)
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
static int socket_get_sndbuf(int sd)
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
const char * addr_family_name(int af)