|
OpenVPN
|
#include "syshead.h"#include "socket.h"#include "fdmisc.h"#include "misc.h"#include "gremlin.h"#include "plugin.h"#include "ps.h"#include "run_command.h"#include "manage.h"#include "openvpn.h"#include "forward.h"#include "resolve.h"#include "memdbg.h"
Go to the source code of this file.
Functions | |
| bool | sockets_read_residual (const struct context *c) |
| static int | socket_get_sndbuf (socket_descriptor_t sd) |
| static void | socket_set_sndbuf (socket_descriptor_t sd, int size) |
| static int | socket_get_rcvbuf (socket_descriptor_t sd) |
| static void | socket_set_rcvbuf (socket_descriptor_t sd, int size) |
| 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. | |
| static bool | socket_set_tcp_nodelay (socket_descriptor_t sd, int state) |
| static void | socket_set_mark (socket_descriptor_t sd, int mark) |
| void | link_socket_update_buffer_sizes (struct link_socket *sock, int rcvbuf, int sndbuf) |
| socket_descriptor_t | create_socket_tcp (struct addrinfo *addrinfo) |
| static socket_descriptor_t | create_socket_udp (struct addrinfo *addrinfo, const unsigned int flags, bool optional) |
| static void | bind_local (const struct link_socket *sock) |
| static void | socket_apply_options (socket_descriptor_t sd, const struct socket_buffer_size *sbs, int mark, const char *bind_dev) |
| 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, –bind-dev and, when bind_addr is given, the local bind (IPV6_V6ONLY per bind_ipv6_only). | |
| static void | create_socket (struct link_socket *sock, struct addrinfo *addr) |
| static void | socket_do_listen (socket_descriptor_t sd, const struct addrinfo *local, bool do_listen, bool do_set_nonblock) |
| socket_descriptor_t | socket_do_accept (socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait) |
| static void | tcp_connection_established (const struct link_socket_actual *act) |
| static socket_descriptor_t | socket_listen_accept (socket_descriptor_t sd, struct link_socket_actual *act, const struct addrinfo *local, bool do_listen, bool nowait, volatile int *signal_received) |
| void | socket_bind (socket_descriptor_t sd, const struct addrinfo *local, int ai_family, const char *prefix, bool ipv6only) |
| int | openvpn_connect (socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received) |
| void | set_actual_address (struct link_socket_actual *actual, struct addrinfo *ai) |
| static void | socket_connect (socket_descriptor_t *sd, const struct sockaddr *dest, const int connect_timeout, struct signal_info *sig_info) |
| static void | stream_buf_init (struct stream_buf *sb, const struct buffer *buf, const unsigned int sockflags, const int proto) |
| static void | stream_buf_close (struct stream_buf *sb) |
| static bool | stream_buf_added (struct stream_buf *sb, ssize_t length_added) |
This will determine if sb->buf contains a full packet. | |
| static void | socket_frame_init (const struct frame *frame, struct link_socket *sock) |
| static void | resolve_bind_local (struct link_socket *sock) |
| static void | resolve_remote (struct link_socket *sock, int phase, struct signal_info *sig_info) |
| struct link_socket * | link_socket_new (void) |
| void | link_socket_init_phase1 (struct context *c, int sock_index, int mode) |
| static void | phase2_set_socket_flags (const struct link_socket *sock) |
| static void | linksock_print_addr (struct link_socket *sock) |
| static void | phase2_tcp_server (struct link_socket *sock, struct signal_info *sig_info) |
| static void | phase2_tcp_client (struct link_socket *sock, struct signal_info *sig_info) |
| static void | phase2_socks_client (struct link_socket *sock, struct signal_info *sig_info) |
| static void | create_socket_dco_win (struct context *c, struct link_socket *sock, struct signal_info *sig_info) |
| void | link_socket_init_phase2 (struct context *c, struct link_socket *sock) |
| void | link_socket_close (struct link_socket *sock) |
| void | setenv_trusted (struct env_set *es, const struct link_socket_info *info) |
| static void | ipchange_fmt (const bool include_cmd, struct argv *argv, const struct link_socket_info *info, struct gc_arena *gc) |
| void | link_socket_connection_initiated (struct link_socket_info *info, const struct link_socket_actual *act, const char *common_name, struct env_set *es) |
| void | link_socket_bad_incoming_addr (struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr) |
| void | link_socket_bad_outgoing_addr (void) |
| in_addr_t | link_socket_current_remote (const struct link_socket_info *info) |
| const struct in6_addr * | link_socket_current_remote_ipv6 (const struct link_socket_info *info) |
| 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) |
| resets the stream buffer to be set up for the next round of reassembling a packet | |
| static struct buffer | stream_buf_get_next (struct stream_buf *sb) |
Return a buffer that is backed by the same backend as sb->buf that determines where the next read should be done by also having the right offset into sb->buf. | |
| static void | stream_buf_get_final (struct stream_buf *sb, struct buffer *buf) |
Sets the parameter buf to the current buffer of sb->buf. | |
| bool | stream_buf_read_setup_dowork (struct stream_buf *sb) |
| Will try to check if the buffers in stream form a full packet. | |
| event_t | socket_listen_event_handle (struct link_socket *s) |
| void | bad_address_length (int actual, int expected) |
| ssize_t | link_socket_read_tcp (struct link_socket *sock, struct buffer *buf) |
| ssize_t | link_socket_write_tcp (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to) |
| static int | socket_get_last_error (const struct link_socket *sock) |
| int | socket_recv_queue (struct link_socket *sock, int maxsize) |
| int | socket_send_queue (struct link_socket *sock, const struct buffer *buf, const struct link_socket_actual *to) |
| static void | read_sockaddr_from_overlapped (const struct overlapped_io *io, struct sockaddr *dst, int overlapped_ret) |
| static int | read_sockaddr_from_packet (struct buffer *buf, struct sockaddr *dst) |
| Extracts a sockaddr from a packet payload. | |
| int | sockethandle_finalize (sockethandle_t sh, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from) |
| unsigned int | socket_set (struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent) |
| void bad_address_length | ( | int | actual, |
| int | expected ) |
Definition at line 1907 of file socket.c.
Referenced by read_sockaddr_from_overlapped(), and socket_recv_queue().
|
static |
Definition at line 264 of file socket.c.
References link_socket_info::af, link_socket_info::bind_ipv6_only, link_socket::bind_local, link_socket_addr::bind_local, link_socket::ctrl_sd, link_socket::info, link_socket_info::lsa, link_socket_info::proto, PROTO_UDP, link_socket::sd, socket_bind(), and link_socket::socks_proxy.
Referenced by create_socket(), and show_connection_entry().
|
static |
Definition at line 330 of file socket.c.
References link_socket_info::af, ASSERT, link_socket::bind_dev, link_socket_info::bind_ipv6_only, bind_local(), link_socket::bind_local, link_socket_addr::bind_local, create_socket_tcp(), create_socket_udp_configured(), link_socket::ctrl_sd, link_socket::info, link_socket_info::lsa, link_socket::mark, link_socket::sd, SF_GETADDRINFO_DGRAM, socket_apply_options(), link_socket::socket_buffer_sizes, link_socket::sockflags, and link_socket::socks_proxy.
Referenced by link_socket_init_phase2().
|
static |
Definition at line 1286 of file socket.c.
References ALLOC_OBJ_CLEAR, tuntap::backend_driver, context::c1, link_socket_addr::current_remote, dco_mp_start_vpn(), tuntap::dco_new_peer_ov, dco_p2p_new_peer(), options::dev_node, DRIVER_DCO, context::gc, tuntap::hand, link_socket::info, linksock_print_addr(), link_socket_info::lsa, options::mode, MODE_POINT_TO_POINT, MODE_SERVER, options::msg_channel, tuntap_options::msg_channel, context::options, tuntap::options, link_socket::sd, SF_DCO_WIN, signal_info::signal_received, link_socket::sockflags, tun_open_device(), and context_1::tuntap.
Referenced by link_socket_init_phase2().
| socket_descriptor_t create_socket_tcp | ( | struct addrinfo * | addrinfo | ) |
Definition at line 177 of file socket.c.
References ASSERT, M_ERR, msg, set_cloexec(), and SOCKET_UNDEFINED.
Referenced by create_socket(), man_connect(), man_listen(), and phase2_tcp_client().
|
static |
Definition at line 209 of file socket.c.
References ASSERT, D_LOW, M_ERR, M_ERRNO, msg, set_cloexec(), SF_USE_IP_PKTINFO, SOCKET_UNDEFINED, and SOL_IP.
Referenced by create_socket_udp_configured().
| 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, –bind-dev and, when bind_addr is given, the local bind (IPV6_V6ONLY per bind_ipv6_only).
Shared by create_socket() and the –server-probe sockets, so a probe socket is the connection socket it may become. A failed bind is fatal; with optional a socket the host cannot create is not, so –server-probe can skip that address family (SOCKET_UNDEFINED is returned).
Definition at line 309 of file socket.c.
References create_socket_udp(), socket_apply_options(), socket_bind(), and SOCKET_UNDEFINED.
Referenced by create_socket().
|
static |
Definition at line 1502 of file socket.c.
References link_socket_addr::actual, openvpn_sockaddr::addr, argv_parse_cmd(), argv_printf(), argv_printf_cat(), link_socket_actual::dest, gc, link_socket_info::ipchange_command, link_socket_info::lsa, print_sockaddr_ex(), PS_SHOW_PORT, and openvpn_sockaddr::sa.
Referenced by link_socket_connection_initiated().
| void link_socket_bad_incoming_addr | ( | struct buffer * | buf, |
| const struct link_socket_info * | info, | ||
| const struct link_socket_actual * | from_addr ) |
Definition at line 1570 of file socket.c.
References openvpn_sockaddr::addr, D_LINK_ERRORS, link_socket_actual::dest, gc, gc_free(), gc_new(), buffer::len, link_socket_info::lsa, msg, print_link_socket_actual(), print_sockaddr_ex(), PS_SHOW_PORT, link_socket_addr::remote_list, and openvpn_sockaddr::sa.
Referenced by process_incoming_link_part1().
| void link_socket_bad_outgoing_addr | ( | void | ) |
Definition at line 1597 of file socket.c.
References D_READ_WRITE, and dmsg.
Referenced by link_socket_get_outgoing_addr().
| void link_socket_close | ( | struct link_socket * | sock | ) |
Definition at line 1444 of file socket.c.
References close_net_event_win32(), link_socket::ctrl_sd, D_LOW, free_buf(), link_socket::listen_handle, M_ERRNO, M_WARN, msg, openvpn_close_socket, overlapped_io_close(), link_socket::reads, link_socket::sd, socket_defined(), SOCKET_UNDEFINED, link_socket::stream_buf, stream_buf_close(), link_socket::stream_buf_data, and link_socket::writes.
Referenced by do_close_link_socket().
| void link_socket_connection_initiated | ( | struct link_socket_info * | info, |
| const struct link_socket_actual * | act, | ||
| const char * | common_name, | ||
| struct env_set * | es ) |
Definition at line 1518 of file socket.c.
References link_socket_addr::actual, alloc_buf_gc(), argv_free(), argv_new(), BSTR, buf_printf(), link_socket_info::connection_established, gc, gc_free(), gc_new(), link_socket_info::ipchange_command, ipchange_fmt(), link_socket_info::lsa, M_INFO, M_WARN, msg, openvpn_run_script(), plugin_call(), plugin_defined(), link_socket_info::plugins, print_link_socket_actual(), setenv_str(), and setenv_trusted().
Referenced by link_socket_set_outgoing_addr().
| in_addr_t link_socket_current_remote | ( | const struct link_socket_info * | info | ) |
Definition at line 1603 of file socket.c.
References link_socket_addr::actual, openvpn_sockaddr::addr, link_socket_addr::current_remote, link_socket_actual::dest, openvpn_sockaddr::in4, IPV4_INVALID_ADDR, link_socket_actual_defined(), link_socket_info::lsa, and openvpn_sockaddr::sa.
Referenced by do_init_route_list().
| const struct in6_addr * link_socket_current_remote_ipv6 | ( | const struct link_socket_info * | info | ) |
Definition at line 1637 of file socket.c.
References link_socket_addr::actual, openvpn_sockaddr::addr, link_socket_addr::current_remote, link_socket_actual::dest, openvpn_sockaddr::in6, link_socket_actual_defined(), link_socket_info::lsa, and openvpn_sockaddr::sa.
Referenced by do_init_route_ipv6_list().
| void link_socket_init_phase1 | ( | struct context * | c, |
| int | sock_index, | ||
| int | mode ) |
Definition at line 979 of file socket.c.
References context_2::accept_from, connection_entry::af, link_socket_info::af, local_list::array, ASSERT, link_socket::bind_dev, options::bind_dev, connection_entry::bind_ipv6_only, link_socket_info::bind_ipv6_only, connection_entry::bind_local, link_socket::bind_local, context::c1, context::c2, options::ce, CM_CHILD_TCP, CM_CHILD_UDP, context_1::dns_cache, link_socket::dns_cache, context_1::http_proxy, link_socket::http_proxy, link_socket::info, options::ipchange, link_socket_info::ipchange_command, context_1::link_socket_addrs, context_2::link_sockets, local_entry::local, link_socket::local_host, connection_entry::local_list, connection_entry::local_port, link_socket::local_port, connection_entry::local_port_defined, LS_MODE_TCP_ACCEPT_FROM, link_socket_info::lsa, link_socket::mark, options::mark, context::mode, link_socket::mode, options::mode, MODE_POINT_TO_POINT, connection_entry::mtu_discover_type, link_socket::mtu_discover_type, context::options, http_proxy_info::options, context::plugins, link_socket_info::plugins, http_proxy_options::port, local_entry::port, socks_proxy_info::port, connection_entry::proto, link_socket_info::proto, local_entry::proto, PROTO_N, PROTO_TCP_CLIENT, PROTO_TCP_SERVER, link_socket::proxy_dest_host, link_socket::proxy_dest_port, options::rcvbuf, socket_buffer_size::rcvbuf, connection_entry::remote, connection_entry::remote_float, link_socket_info::remote_float, link_socket::remote_host, connection_entry::remote_port, link_socket::remote_port, resolve_bind_local(), resolve_remote(), link_socket::resolve_retry_seconds, options::resolve_retry_seconds, link_socket::sd, http_proxy_options::server, socks_proxy_info::server, context_2::server_poll_interval, link_socket::server_poll_timeout, SF_PORT_SHARE, options::sndbuf, socket_buffer_size::sndbuf, link_socket::socket_buffer_sizes, link_socket::sockflags, options::sockflags, context_1::socks_proxy, and link_socket::socks_proxy.
Referenced by do_init_socket_phase1().
| void link_socket_init_phase2 | ( | struct context * | c, |
| struct link_socket * | sock ) |
Definition at line 1334 of file socket.c.
References link_socket_addr::actual, openvpn_sockaddr::addr, addr_family_name(), link_socket_info::af, ASSERT, link_socket::bind_local, link_socket_addr::bind_local, context::c2, create_socket(), create_socket_dco_win(), link_socket_addr::current_remote, dco_enabled(), link_socket_actual::dest, context_2::frame, link_socket::info, linksock_print_addr(), link_socket_info::lsa, M_WARN, msg, context::options, phase2_set_socket_flags(), phase2_socks_client(), phase2_tcp_client(), phase2_tcp_server(), link_socket_info::proto, PROTO_TCP_CLIENT, PROTO_TCP_SERVER, PROTO_UDP, register_signal(), link_socket::remote_host, resolve_remote(), openvpn_sockaddr::sa, link_socket::sd, context::sig, SIG_SOURCE_HARD, siginfo_static, signal_info::signal_received, signal_reset(), signal_info::signal_text, SIGUSR1, socket_frame_init(), SOCKET_UNDEFINED, link_socket::socks_proxy, signal_info::source, and throw_signal().
Referenced by do_init_socket_phase2().
| struct link_socket * link_socket_new | ( | void | ) |
Definition at line 965 of file socket.c.
References ALLOC_OBJ_CLEAR, link_socket::ctrl_sd, link_socket::ev_arg, EVENT_ARG_LINK_SOCKET, link_socket::sd, event_arg::sock, SOCKET_UNDEFINED, event_arg::type, and event_arg::u.
Referenced by do_link_socket_new().
| ssize_t link_socket_read_tcp | ( | struct link_socket * | sock, |
| struct buffer * | buf ) |
Definition at line 1919 of file socket.c.
References BLENZ, BPTR, buffer::len, M_INFO, msg, MSG_NOSIGNAL, link_socket::reads, stream_buf::residual_fully_formed, link_socket::sd, SOCKET_UNDEFINED, sockethandle_finalize(), link_socket::stream_buf, stream_buf_added(), stream_buf_get_final(), stream_buf_get_next(), stream_buf_reset(), and link_socket::stream_reset.
Referenced by link_socket_read().
| void link_socket_update_buffer_sizes | ( | struct link_socket * | sock, |
| int | rcvbuf, | ||
| int | sndbuf ) |
Definition at line 161 of file socket.c.
References socket_buffer_size::rcvbuf, link_socket::sd, socket_buffer_size::sndbuf, link_socket::socket_buffer_sizes, socket_defined(), and socket_set_buffers().
Referenced by do_deferred_options().
| ssize_t link_socket_write_tcp | ( | struct link_socket * | sock, |
| struct buffer * | buf, | ||
| struct link_socket_actual * | to ) |
Definition at line 2101 of file socket.c.
References ASSERT, BLEN, buf_write_prepend(), D_STREAM_DEBUG, dmsg, htonps, link_socket_write_win32(), stream_buf::maxlen, buffer::offset, and PACKET_SIZE_MAX.
Referenced by link_socket_write().
|
static |
Definition at line 1146 of file socket.c.
References link_socket_addr::actual, openvpn_sockaddr::addr, link_socket_info::af, ASSERT, link_socket::bind_local, link_socket_addr::bind_local, D_INIT_MEDIUM, link_socket_actual::dest, gc, gc_free(), gc_new(), link_socket::info, LS_MODE_TCP_ACCEPT_FROM, link_socket_info::lsa, M_INFO, link_socket::mode, msg, print_link_socket_actual_ex(), print_sockaddr(), link_socket_info::proto, proto2ascii(), PS_SHOW_PORT_IF_DEFINED, and openvpn_sockaddr::sa.
Referenced by create_socket_dco_win(), and link_socket_init_phase2().
| int openvpn_connect | ( | socket_descriptor_t | sd, |
| const struct sockaddr * | remote, | ||
| int | connect_timeout, | ||
| volatile int * | signal_received ) |
Definition at line 608 of file socket.c.
References af_addr_size(), get_signal(), management_sleep(), openvpn_errno, openvpn_fd_set(), openvpn_select(), set_nonblock(), and status.
Referenced by man_connect(), and socket_connect().
|
static |
Definition at line 1123 of file socket.c.
References link_socket_info::af, link_socket::info, link_socket::mtu_discover_type, link_socket_info::proto, proto_is_tcp(), link_socket::sd, set_mtu_discover_type(), set_nonblock(), SF_DCO_WIN, socket_set_tcp_nodelay(), and link_socket::sockflags.
Referenced by link_socket_init_phase2().
|
static |
Definition at line 1252 of file socket.c.
References link_socket_addr::actual, addr_zero_host(), link_socket::ctrl_sd, link_socket_addr::current_remote, link_socket_actual::dest, establish_socks_proxy_udpassoc(), get_server_poll_remaining_time(), link_socket::info, link_socket_info::lsa, link_socket::proxy_dest_host, link_socket::proxy_dest_port, link_socket::remote_host, link_socket_addr::remote_list, link_socket::remote_port, resolve_remote(), link_socket::server_poll_timeout, signal_info::signal_received, socket_connect(), link_socket::socks_proxy, and link_socket::socks_relay.
Referenced by link_socket_init_phase2().
|
static |
Definition at line 1217 of file socket.c.
References create_socket_tcp(), link_socket_addr::current_remote, establish_http_proxy_passthru(), establish_socks_proxy_passthru(), get_server_poll_remaining_time(), link_socket::http_proxy, link_socket::info, link_socket_info::lsa, openvpn_close_socket, link_socket::proxy_dest_host, link_socket::proxy_dest_port, stream_buf::residual, link_socket::sd, link_socket::server_poll_timeout, signal_info::signal_received, socket_connect(), link_socket::socks_proxy, and link_socket::stream_buf.
Referenced by link_socket_init_phase2().
|
static |
Definition at line 1183 of file socket.c.
References link_socket_addr::actual, ASSERT, link_socket_addr::bind_local, link_socket::info, LS_MODE_DEFAULT, LS_MODE_TCP_ACCEPT_FROM, LS_MODE_TCP_LISTEN, link_socket_info::lsa, link_socket::mode, register_signal(), link_socket::sd, signal_info::signal_received, SIGTERM, socket_defined(), socket_do_accept(), socket_do_listen(), socket_listen_accept(), and tcp_connection_established().
Referenced by link_socket_init_phase2().
|
static |
Definition at line 2417 of file socket.c.
References overlapped_io::addr, overlapped_io::addr6, overlapped_io::addr_defined, overlapped_io::addrlen, af_addr_size(), bad_address_length(), and CLEAR.
Referenced by sockethandle_finalize().
|
static |
Extracts a sockaddr from a packet payload.
Reads a sockaddr structure from the start of the packet buffer and writes it to dst.
| [in] | buf | Packet buffer containing the payload. |
| [out] | dst | Destination buffer for the extracted sockaddr. |
Definition at line 2467 of file socket.c.
References ASSERT, BPTR, buf_advance(), and buf_len().
Referenced by sockethandle_finalize().
|
static |
Definition at line 804 of file socket.c.
References link_socket_info::af, link_socket_addr::bind_local, link_socket::dns_cache, gc, gc_free(), gc_new(), get_cached_dns_entry(), GETADDR_DATAGRAM, GETADDR_FATAL, GETADDR_PASSIVE, GETADDR_RESOLVE, GETADDR_WARN_ON_SIGNAL, link_socket::info, link_socket::local_host, link_socket::local_port, link_socket_info::lsa, M_FATAL, msg, openvpn_getaddrinfo(), link_socket_info::proto, proto_is_dgram(), and status.
Referenced by link_socket_init_phase1().
|
static |
Definition at line 854 of file socket.c.
References link_socket_addr::actual, link_socket_info::af, ASSERT, CLEAR, link_socket_addr::current_remote, D_SOCKET_DEBUG, dmsg, link_socket::dns_cache, gc, gc_free(), gc_new(), get_cached_dns_entry(), GETADDR_DATAGRAM, GETADDR_FATAL, GETADDR_MENTION_RESOLVE_RETRY, GETADDR_RESOLVE, GETADDR_TRY_ONCE, GETADDR_UPDATE_MANAGEMENT_STATE, link_socket::info, link_socket_actual_defined(), link_socket_info::lsa, M_INFO, msg, openvpn_getaddrinfo(), print_link_socket_actual(), link_socket_info::proto, proto_is_dgram(), register_signal(), link_socket::remote_host, link_socket_addr::remote_list, link_socket::remote_port, RESOLV_RETRY_INFINITE, link_socket::resolve_retry_seconds, set_actual_address(), sf2gaf(), signal_info::signal_received, SIGUSR1, link_socket::sockflags, and status.
Referenced by link_socket_init_phase1(), link_socket_init_phase2(), and phase2_socks_client().
| void set_actual_address | ( | struct link_socket_actual * | actual, |
| struct addrinfo * | ai ) |
Definition at line 701 of file socket.c.
References openvpn_sockaddr::addr, ASSERT, CLEAR, link_socket_actual::dest, openvpn_sockaddr::in4, and openvpn_sockaddr::in6.
Referenced by resolve_remote().
| void setenv_trusted | ( | struct env_set * | es, |
| const struct link_socket_info * | info ) |
Definition at line 1496 of file socket.c.
References link_socket_addr::actual, link_socket_info::lsa, SA_IP_PORT, and setenv_link_socket_actual().
Referenced by link_socket_connection_initiated(), multi_client_connect_setenv(), and multi_client_disconnect_setenv().
|
static |
Definition at line 283 of file socket.c.
References M_ERRNO, M_INFO, M_WARN, msg, socket_set_buffers(), and socket_set_mark().
Referenced by create_socket(), and create_socket_udp_configured().
| void socket_bind | ( | socket_descriptor_t | sd, |
| const struct addrinfo * | local, | ||
| int | ai_family, | ||
| const char * | prefix, | ||
| bool | ipv6only ) |
Definition at line 560 of file socket.c.
References addr_family_name(), ASSERT, gc, gc_free(), gc_new(), M_ERRNO, M_FATAL, M_INFO, M_NONFATAL, msg, openvpn_bind(), print_sockaddr_ex(), and PS_SHOW_PORT.
Referenced by bind_local(), create_socket_udp_configured(), and man_listen().
|
static |
Definition at line 721 of file socket.c.
References D_LINK_ERRORS, gc, gc_free(), gc_new(), get_signal(), M_INFO, management_set_state(), msg, openvpn_close_socket, openvpn_connect(), OPENVPN_STATE_TCP_CONNECT, print_sockaddr(), register_signal(), signal_info::signal_received, SIGUSR1, SOCKET_UNDEFINED, and status.
Referenced by phase2_socks_client(), and phase2_tcp_client().
| socket_descriptor_t socket_do_accept | ( | socket_descriptor_t | sd, |
| struct link_socket_actual * | act, | ||
| const bool | nowait ) |
Definition at line 426 of file socket.c.
References openvpn_sockaddr::addr, af_addr_size(), CLEAR, D_LINK_ERRORS, link_socket_actual::dest, M_ERRNO, msg, openvpn_close_socket, openvpn_sockaddr::sa, set_cloexec(), socket_defined(), and SOCKET_UNDEFINED.
Referenced by man_accept(), phase2_tcp_server(), and socket_listen_accept().
|
static |
Definition at line 401 of file socket.c.
References ASSERT, gc, gc_free(), gc_new(), M_ERR, M_INFO, msg, print_sockaddr(), and set_nonblock().
Referenced by phase2_tcp_server(), and socket_listen_accept().
|
static |
Definition at line 780 of file socket.c.
References alloc_buf_sock_tun(), overlapped_io::buf_init, link_socket::info, link_socket_connection_oriented(), overlapped_io::overlapped, overlapped_io_init(), link_socket_info::proto, rw_handle::read, link_socket::reads, link_socket::rw_handle, link_socket::sockflags, link_socket::stream_buf, link_socket::stream_buf_data, stream_buf_init(), rw_handle::write, and link_socket::writes.
Referenced by link_socket_init_phase2().
|
static |
Definition at line 2205 of file socket.c.
References socket_is_dco_win().
Referenced by socket_recv_queue(), and socket_send_queue().
|
static |
Definition at line 81 of file socket.c.
Referenced by socket_set_buffers().
|
static |
Definition at line 59 of file socket.c.
Referenced by socket_set_buffers().
|
static |
Definition at line 498 of file socket.c.
References CLEAR, D_LINK_ERRORS, gc, gc_free(), gc_new(), get_signal(), M_ERR, M_ERRNO, management_sleep(), msg, openvpn_close_socket, openvpn_fd_set(), openvpn_select(), socket_defined(), socket_do_accept(), socket_do_listen(), SOCKET_UNDEFINED, status, and tcp_connection_established().
Referenced by phase2_tcp_server().
| event_t socket_listen_event_handle | ( | struct link_socket * | s | ) |
Definition at line 1888 of file socket.c.
References defined_net_event_win32(), init_net_event_win32(), link_socket::listen_handle, and link_socket::sd.
Referenced by socket_set_listen_persistent().
| int socket_recv_queue | ( | struct link_socket * | sock, |
| int | maxsize ) |
Definition at line 2216 of file socket.c.
References overlapped_io::addr, overlapped_io::addr6, overlapped_io::addr_defined, overlapped_io::addrlen, link_socket_info::af, af_addr_size(), ASSERT, bad_address_length(), BLEN, BSTR, overlapped_io::buf, overlapped_io::buf_init, D_WIN32_IO, dmsg, overlapped_io::flags, gc, gc_free(), gc_new(), link_socket::info, overlapped_io::iostate, IOSTATE_IMMEDIATE_RETURN, IOSTATE_INITIAL, IOSTATE_QUEUED, overlapped_io::overlapped, link_socket_info::proto, proto_is_tcp(), proto_is_udp(), link_socket::reads, link_socket::sd, overlapped_io::size, socket_get_last_error(), socket_is_dco_win(), overlapped_io::status, status, link_socket::stream_buf, stream_buf_get_next(), and strerror_win32().
Referenced by socket_set().
| int socket_send_queue | ( | struct link_socket * | sock, |
| const struct buffer * | buf, | ||
| const struct link_socket_actual * | to ) |
Definition at line 2316 of file socket.c.
References openvpn_sockaddr::addr, overlapped_io::addr, overlapped_io::addr6, overlapped_io::addr_defined, overlapped_io::addrlen, ASSERT, BLEN, BSTR, overlapped_io::buf, buf_copy(), overlapped_io::buf_init, D_WIN32_IO, link_socket_actual::dest, dmsg, overlapped_io::flags, gc, gc_free(), gc_new(), openvpn_sockaddr::in4, openvpn_sockaddr::in6, link_socket::info, overlapped_io::iostate, IOSTATE_IMMEDIATE_RETURN, IOSTATE_INITIAL, IOSTATE_QUEUED, buffer::len, overlapped_io::overlapped, link_socket_info::proto, proto_is_tcp(), proto_is_udp(), openvpn_sockaddr::sa, link_socket::sd, overlapped_io::size, socket_get_last_error(), socket_is_dco_win(), overlapped_io::status, status, strerror_win32(), and link_socket::writes.
Referenced by link_socket_write_win32().
| unsigned int socket_set | ( | struct link_socket * | s, |
| struct event_set * | es, | ||
| unsigned int | rwflags, | ||
| void * | arg, | ||
| unsigned int * | persistent ) |
Definition at line 2594 of file socket.c.
References ASSERT, event_ctl(), EVENT_READ, link_socket::rwflags_debug, socket_event_handle(), socket_recv_queue(), and stream_buf_read_setup().
Referenced by multi_io_process_flags(), and multi_tcp_set_global_rw_flags().
| 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.
| fd | The socket to modify |
| sbs | new sizes. |
| reduce_size | apply the new size even if smaller than current one |
Definition at line 103 of file socket.c.
References D_OSBUF, msg, socket_buffer_size::rcvbuf, socket_buffer_size::sndbuf, socket_get_rcvbuf(), socket_get_sndbuf(), socket_set_rcvbuf(), and socket_set_sndbuf().
Referenced by link_socket_update_buffer_sizes(), open_tun_afunix(), and socket_apply_options().
|
inlinestatic |
Definition at line 150 of file socket.c.
Referenced by socket_apply_options().
|
static |
Definition at line 94 of file socket.c.
Referenced by socket_set_buffers().
|
static |
Definition at line 72 of file socket.c.
Referenced by socket_set_buffers().
|
static |
| const char * socket_stat | ( | const struct link_socket * | s, |
| unsigned int | rwflags, | ||
| struct gc_arena * | gc ) |
Definition at line 1670 of file socket.c.
References alloc_buf_gc(), BSTR, buf_printf(), EVENT_READ, EVENT_WRITE, gc, overlapped_io_state_ascii(), link_socket::reads, link_socket::rwflags_debug, and link_socket::writes.
Referenced by wait_status_string().
| int sockethandle_finalize | ( | sockethandle_t | sh, |
| struct overlapped_io * | io, | ||
| struct buffer * | buf, | ||
| struct link_socket_actual * | from ) |
Definition at line 2501 of file socket.c.
References openvpn_sockaddr::addr, ASSERT, overlapped_io::buf, D_WIN32_IO, link_socket_actual::dest, dmsg, overlapped_io::iostate, IOSTATE_IMMEDIATE_RETURN, IOSTATE_INITIAL, IOSTATE_QUEUED, sockethandle_t::is_handle, buffer::len, M_ERRNO, msg, overlapped_io::overlapped, sockethandle_t::prepend_sa, read_sockaddr_from_overlapped(), read_sockaddr_from_packet(), openvpn_sockaddr::sa, overlapped_io::size, SocketHandleGetLastError(), SocketHandleGetOverlappedResult(), SocketHandleSetInvalError(), SocketHandleSetLastError(), overlapped_io::status, and status.
Referenced by link_socket_read_tcp(), link_socket_read_udp_win32(), link_socket_write_win32(), read_incoming_tun(), and tun_write_win32().
| bool sockets_read_residual | ( | const struct context * | c | ) |
Definition at line 46 of file socket.c.
References context::c1, context::c2, context_2::link_sockets, context_1::link_sockets_num, stream_buf::residual_fully_formed, and link_socket::stream_buf.
Referenced by io_wait(), and multi_io_post().
|
static |
This will determine if sb->buf contains a full packet.
It will also move anything in sb->buf beyond a full packet to sb->residual.
The first time the function is called with a valid buffer and port sharing is enabled, the function will also determine if the buffer contains OpenVPN protocol data and store the result in sb->port_share_state.
If a packet outside the allowed range is detected, the error state on sb is set.
Since the buffer in sb->buf is modified from the outside (via stream_buf_get_next) the parameter length_added needs to be set to the amount of bytes that have been written to this buffer. If the buffer was not modified but should still be analysed and potentially split to sb->residual, the parameter length_added should be 0.
| sb | the stream buffer |
| length_added | The length that has been added to sb->buf |
sb->buf contains fully reassembled packet Definition at line 1810 of file socket.c.
References ASSERT, BLEN, stream_buf::buf, buf_copy_excess(), buf_init, buf_read(), D_PS_PROXY, D_STREAM_DEBUG, dmsg, stream_buf::error, buffer::len, stream_buf::len, M_WARN, stream_buf::maxlen, msg, ntohps, stream_buf::residual, and stream_buf_reset().
Referenced by link_socket_read_tcp(), and stream_buf_read_setup_dowork().
|
static |
Definition at line 1877 of file socket.c.
References free_buf(), and stream_buf::residual.
Referenced by link_socket_close().
|
inlinestatic |
Sets the parameter buf to the current buffer of sb->buf.
This function assumes that caller already checked if the packet in sb->buf is fully assembled.
| sb | stream buffer to operate on |
| buf | buffer to point to the contents of buf |
Definition at line 1766 of file socket.c.
References ASSERT, stream_buf::buf, buf_defined(), D_STREAM_DEBUG, dmsg, and buffer::len.
Referenced by link_socket_read_tcp().
|
inlinestatic |
Return a buffer that is backed by the same backend as sb->buf that determines where the next read should be done by also having the right offset into sb->buf.
| sb | the stream buffer from which to construct the next buffer |
Definition at line 1743 of file socket.c.
References ASSERT, buf_safe(), D_STREAM_DEBUG, dmsg, buffer::len, buffer::offset, and stream_buf_get_next().
Referenced by link_socket_read_tcp(), socket_recv_queue(), and stream_buf_get_next().
|
static |
Definition at line 1719 of file socket.c.
References alloc_buf(), stream_buf::buf_init, D_STREAM_DEBUG, dmsg, stream_buf::error, buffer::len, stream_buf::maxlen, PROTO_TCP_SERVER, stream_buf::residual, SF_PORT_SHARE, and stream_buf_reset().
Referenced by socket_frame_init().
| bool stream_buf_read_setup_dowork | ( | struct stream_buf * | sb | ) |
Will try to check if the buffers in stream form a full packet.
Will return true if further reads are required and false otherwise. (full packet is ready)
With UDP we always return true as there is no reassembly.
| sb | the stream buffer that should be worked on |
Definition at line 1774 of file socket.c.
References ASSERT, stream_buf::buf, buf_copy(), buf_init, D_STREAM_DEBUG, dmsg, buffer::len, stream_buf::residual, stream_buf::residual_fully_formed, and stream_buf_added().
Referenced by stream_buf_read_setup().
|
inlinestatic |
resets the stream buffer to be set up for the next round of reassembling a packet
But still leaves the current packet in sb->buf to be potentially read.
Definition at line 1710 of file socket.c.
References stream_buf::buf, stream_buf::buf_init, D_STREAM_DEBUG, dmsg, stream_buf::len, and stream_buf::residual_fully_formed.
Referenced by link_socket_read_tcp(), stream_buf_added(), and stream_buf_init().
|
static |
Definition at line 490 of file socket.c.
References gc, gc_free(), gc_new(), M_INFO, msg, and print_link_socket_actual().
Referenced by phase2_tcp_server(), and socket_listen_accept().