42#define OPENVPN_PORT "1194"
48#define RESOLV_RETRY_INFINITE 1000000000
57#define PACKET_SIZE_MAX UINT16_MAX
60#define htonps(x) htons(x)
63#define ntohps(x) ntohs(x)
127 int port_share_state;
187#define LS_MODE_DEFAULT 0
188#define LS_MODE_TCP_LISTEN 1
189#define LS_MODE_TCP_ACCEPT_FROM 2
199#define SF_USE_IP_PKTINFO (1 << 0)
200#define SF_TCP_NODELAY (1 << 1)
201#define SF_PORT_SHARE (1 << 2)
202#define SF_HOST_RANDOMIZE (1 << 3)
203#define SF_GETADDRINFO_DGRAM (1 << 4)
204#define SF_DCO_WIN (1 << 5)
205#define SF_PREPEND_SA (1 << 6)
206#define SF_PKTINFO_COPY_IIF (1 << 7)
231#if PASSTOS_CAPABILITY
233#if defined(TARGET_LINUX)
251#define MSG_NOSIGNAL 0
256#define openvpn_close_socket(s) closesocket(s)
288 return sh.
is_handle ? (int)GetLastError() : WSAGetLastError();
294 sh.
is_handle ? SetLastError(err) : WSASetLastError(err);
300 sh.
is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
308 fd_set *exceptfds,
struct timeval *timeout)
311 return select(0, readfds, writefds, exceptfds, timeout);
318 return send(sockfd, buf, (
int)len, flags);
324 ASSERT(addrlen <= INT_MAX);
325 return bind(sockfd, addr, (
int)addrlen);
330#define openvpn_close_socket(s) close(s)
331#define openvpn_select(nfds, readfds, writefds, exceptfds, timeout) \
332 select(nfds, readfds, writefds, exceptfds, timeout)
333#define openvpn_send(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
334#define openvpn_bind(sockfd, addr, addrlen) bind(sockfd, addr, addrlen)
341 const char *prefix,
bool ipv6only);
344 volatile int *signal_received);
356#ifdef ENABLE_MANAGEMENT
365#define IPV4_INVALID_ADDR 0xffffffff
372 const char *common_name,
struct env_set *es);
401 const char *bind_dev,
struct addrinfo *bind_addr,
402 bool bind_ipv6_only,
bool optional);
411void socket_bind_unix(
socket_descriptor_t sd,
struct sockaddr_un *local,
const char *prefix);
417void sockaddr_unix_init(
struct sockaddr_un *local,
const char *path);
419const char *sockaddr_unix_name(
const struct sockaddr_un *local,
const char *null);
421void socket_delete_unix(
const struct sockaddr_un *local);
443socket_foreign_protocol_detected(
const struct link_socket *sock)
448static inline const struct buffer *
449socket_foreign_protocol_head(
const struct link_socket *sock)
455socket_foreign_protocol_sd(
const struct link_socket *sock)
475 return err == WSAECONNRESET || err == WSAECONNABORTED
476 || err == ERROR_CONNECTION_ABORTED;
478 return err == ECONNRESET;
534 const char *common_name,
struct env_set *es)
610ssize_t link_socket_read_udp_posix(
const struct link_socket *sock,
struct buffer *buf,
628 res = link_socket_read_udp_posix(sock, buf, from);
696ssize_t link_socket_write_udp_posix_sendmsg(
const struct link_socket *sock,
const struct buffer *buf,
701link_socket_write_udp_posix(
const struct link_socket *sock,
const struct buffer *buf,
706 && addr_defined_ipi(to))
708 return link_socket_write_udp_posix_sendmsg(sock, buf, to);
717link_socket_write_tcp_posix(
const struct link_socket *sock,
const struct buffer *buf)
730 return link_socket_write_udp_posix(sock, buf, to);
754#if PASSTOS_CAPABILITY
765 sock->ptos = iph->
tos;
766 sock->ptos_defined =
true;
777 if (sock && sock->ptos_defined)
779 setsockopt(sock->
sd, IPPROTO_IP, IP_TOS, (
const void *)&sock->ptos,
sizeof(sock->ptos));
809 void *arg,
unsigned int *persistent);
Buffer management functions and garbage collection.
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
Prepend data to a buffer.
#define CBPTR(buf)
Return a const pointer to the start of the buffer content.
#define BLEN(buf)
Return the length of the buffer content in bytes.
#define BLENZ(buf)
Return the length of the buffer content as a size_t.
const struct rw_handle * event_t
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
static SERVICE_STATUS status
void link_socket_init_phase1(struct context *c, int sock_index, int mode)
static event_t socket_event_handle(const struct link_socket *sock)
const char * socket_stat(const struct link_socket *sock, unsigned int rwflags, struct gc_arena *gc)
static BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *io)
static ssize_t link_socket_read(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
void link_socket_init_phase2(struct context *c, struct link_socket *sock)
ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
static bool socket_connection_reset(const struct link_socket *sock, ssize_t status)
event_t socket_listen_event_handle(struct link_socket *sock)
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
void set_actual_address(struct link_socket_actual *actual, struct addrinfo *ai)
void socket_bind(socket_descriptor_t sd, const struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
static ssize_t link_socket_write(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
static bool link_socket_verify_incoming_addr(const struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
void bad_address_length(int actual, int expected)
static bool link_socket_connection_oriented(const struct link_socket *sock)
static bool stream_buf_read_setup(struct link_socket *sock)
void sd_close(socket_descriptor_t *sd)
static void socket_reset_listen_persistent(struct link_socket *sock)
static int link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
static void SocketHandleSetLastError(sockethandle_t sh, DWORD err)
socket_descriptor_t create_socket_tcp(struct addrinfo *)
static int SocketHandleGetLastError(sockethandle_t sh)
static void SocketHandleSetInvalError(sockethandle_t sh)
ssize_t link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
int socket_recv_queue(struct link_socket *sock, int maxsize)
void link_socket_close(struct link_socket *sock)
static void link_socket_set_outgoing_addr(struct link_socket_info *info, const struct link_socket_actual *act, const char *common_name, struct env_set *es)
void socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size *sbs, bool reduce_size)
Sets the receive and send buffer sizes of a socket descriptor.
bool stream_buf_read_setup_dowork(struct stream_buf *sb)
Will try to check if the buffers in stream form a full packet.
static void link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
#define SF_USE_IP_PKTINFO
int socket_send_queue(struct link_socket *sock, const struct buffer *buf, const struct link_socket_actual *to)
uint16_t packet_size_type
void link_socket_bad_outgoing_addr(void)
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.
int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
unsigned int socket_set(struct link_socket *sock, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
static int openvpn_select(socket_descriptor_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
static ssize_t link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
static int link_socket_write_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
struct link_socket * link_socket_new(void)
void link_socket_connection_initiated(struct link_socket_info *info, const struct link_socket_actual *addr, const char *common_name, struct env_set *es)
bool sockets_read_residual(const struct context *c)
socket_descriptor_t create_socket_udp_configured(sa_family_t af, unsigned int sockflags, const struct socket_buffer_size *sbs, int mark, const char *bind_dev, struct addrinfo *bind_addr, bool bind_ipv6_only, bool optional)
Create a UDP socket for af set up the way a link socket is: –sndbuf/–rcvbuf, –mark,...
static int openvpn_bind(socket_descriptor_t sockfd, const struct sockaddr *addr, size_t addrlen)
void setenv_trusted(struct env_set *es, const struct link_socket_info *info)
static ssize_t openvpn_send(socket_descriptor_t sockfd, const void *buf, size_t len, int flags)
static bool link_socket_actual_defined(const struct link_socket_actual *act)
static bool addr_match_proto(const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2, const int proto)
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
static bool addrlist_match_proto(const struct openvpn_sockaddr *a1, const struct addrinfo *addr_list, const int proto)
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
static int af_addr_size(sa_family_t af)
static bool link_socket_proto_connection_oriented(int proto)
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Contains all state information for one tunnel.
Garbage collection arena used to keep track of dynamically allocated memory.
struct openvpn_sockaddr dest
struct link_socket_actual actual
struct addrinfo * remote_list
struct addrinfo * bind_local
struct addrinfo * current_remote
bool connection_established
struct link_socket_addr * lsa
const char * ipchange_command
const struct plugin_list * plugins
struct event_timeout * server_poll_timeout
unsigned int rwflags_debug
struct socket_buffer_size socket_buffer_sizes
struct link_socket_actual socks_relay
struct rw_handle listen_handle
struct link_socket_info info
const char * proxy_dest_port
struct rw_handle rw_handle
struct overlapped_io writes
bool listen_persistent_queued
socket_descriptor_t ctrl_sd
struct stream_buf stream_buf
struct socks_proxy_info * socks_proxy
int resolve_retry_seconds
const char * proxy_dest_host
struct http_proxy_info * http_proxy
struct cached_dns_entry * dns_cache
struct buffer stream_buf_data
struct event_arg ev_arg
this struct will store a pointer to either mi or link_socket, depending on the event type,...
struct overlapped_io reads
union openvpn_sockaddr::@051240265251124304325377241125360350250341115171 addr
struct used to extract packets encapsulated in streams into a buffer, in this case OpenVPN packets (d...
struct buffer buf
Holds the data of the current packet.
bool error
if true, a fatal TCP error has occurred, requiring that connection be restarted
struct buffer residual
buffer holding the excess bytes that are not part of the packet.
bool residual_fully_formed
The buffer in buf contains a full packet without a header.
int maxlen
Maximum length of a packet that we accept.
int len
-1 if not yet known.
unsigned short sa_family_t
SOCKET socket_descriptor_t
long reset_net_event_win32(struct rw_handle *event, socket_descriptor_t sd)
static bool overlapped_io_active(const struct overlapped_io *o)