OpenVPN
|
#include "syshead.h"
#include "dco.h"
#include "forward.h"
#include "tun.h"
#include "crypto.h"
#include "ssl_common.h"
#include "openvpn.h"
#include <bcrypt.h>
#include <winsock2.h>
#include <ws2tcpip.h>
Go to the source code of this file.
Functions | |
static void | dco_wait_ready (DWORD idx) |
static bool | dco_get_version (OVPN_VERSION *version) |
Gets version of dco-win driver. | |
void | ovpn_dco_init_mp (dco_context_t *dco, const char *dev_node) |
Initializes the DCO adapter in multipeer mode and sets it to "connected" state. | |
void | dco_p2p_start_vpn (struct tuntap *tt) |
Transitions the DCO adapter to the connected state in P2P mode. | |
bool | ovpn_dco_init (int mode, dco_context_t *dco, const char *dev_node) |
Initializes DCO depends on mode | |
int | open_tun_dco (struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev) |
static void | dco_connect_wait (HANDLE handle, OVERLAPPED *ov, int timeout, struct signal_info *sig_info) |
void | dco_mp_start_vpn (HANDLE handle, struct link_socket *sock) |
Initializes and binds the kernel UDP transport socket for multipeer mode. | |
void | dco_p2p_new_peer (HANDLE handle, struct link_socket *sock, struct signal_info *sig_info) |
int | dco_new_peer (dco_context_t *dco, unsigned int peerid, int sd, struct sockaddr *localaddr, struct sockaddr *remoteaddr, struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6) |
int | dco_del_peer (dco_context_t *dco, unsigned int peerid) |
int | dco_set_peer (dco_context_t *dco, unsigned int peerid, int keepalive_interval, int keepalive_timeout, int mss) |
int | dco_new_key (dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slot_t slot, const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const uint8_t *decrypt_key, const uint8_t *decrypt_iv, const char *ciphername) |
int | dco_del_key (dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) |
int | dco_swap_keys (dco_context_t *dco, unsigned int peer_id) |
bool | dco_available (int msglevel) |
const char * | dco_version_string (struct gc_arena *gc) |
static void | dco_handle_overlapped_success (dco_context_t *dco, bool queued) |
Handles successful completion of overlapped operation. | |
int | dco_do_read (dco_context_t *dco) |
int | dco_get_peer_stats_multi (dco_context_t *dco, struct multi_context *m, const bool raise_sigusr1_on_err) |
int | dco_get_peer_stats (struct context *c, const bool raise_sigusr1_on_err) |
void | dco_event_set (dco_context_t *dco, struct event_set *es, void *arg) |
const char * | dco_get_supported_ciphers (void) |
bool | dco_win_supports_multipeer (void) |
void | dco_win_add_iroute_ipv4 (dco_context_t *dco, in_addr_t dst, unsigned int netbits, unsigned int peer_id) |
void | dco_win_add_iroute_ipv6 (dco_context_t *dco, struct in6_addr dst, unsigned int netbits, unsigned int peer_id) |
void | dco_win_del_iroute_ipv4 (dco_context_t *dco, in_addr_t dst, unsigned int netbits) |
void | dco_win_del_iroute_ipv6 (dco_context_t *dco, struct in6_addr dst, unsigned int netbits) |
|
static |
Definition at line 219 of file dco_win.c.
References get_signal(), M_ERR, M_ERRNO, M_NONFATAL, management_sleep(), msg, register_signal(), and signal_info::signal_received.
Referenced by dco_p2p_new_peer().
int dco_del_key | ( | dco_context_t * | dco, |
unsigned int | peerid, | ||
dco_key_slot_t | slot | ||
) |
int dco_del_peer | ( | dco_context_t * | dco, |
unsigned int | peerid | ||
) |
Definition at line 465 of file dco_win.c.
References D_DCO_DEBUG, M_ERRNO, M_WARN, msg, OVPN_IOCTL_DEL_PEER, and OVPN_IOCTL_MP_DEL_PEER.
int dco_do_read | ( | dco_context_t * | dco | ) |
Definition at line 674 of file dco_win.c.
References ASSERT, D_DCO_DEBUG, dco_handle_overlapped_success(), IOSTATE_IMMEDIATE_RETURN, IOSTATE_INITIAL, IOSTATE_QUEUED, buffer::len, M_ERRNO, and msg.
void dco_event_set | ( | dco_context_t * | dco, |
struct event_set * | es, | ||
void * | arg | ||
) |
Definition at line 752 of file dco_win.c.
References ASSERT, D_DCO_DEBUG, tuntap::dco, es, event_ctl(), EVENT_READ, IOSTATE_IMMEDIATE_RETURN, IOSTATE_INITIAL, IOSTATE_QUEUED, M_ERRNO, msg, and OVPN_IOCTL_NOTIFY_EVENT.
int dco_get_peer_stats | ( | struct context * | c, |
const bool | raise_sigusr1_on_err | ||
) |
Definition at line 723 of file dco_win.c.
References context::c1, context::c2, context_2::dco_read_bytes, context_2::dco_write_bytes, tuntap::hand, M_ERRNO, M_WARN, msg, OVPN_IOCTL_GET_STATS, _OVPN_STATS::TransportBytesReceived, _OVPN_STATS::TransportBytesSent, context_2::tun_read_bytes, context_2::tun_write_bytes, _OVPN_STATS::TunBytesReceived, _OVPN_STATS::TunBytesSent, context_1::tuntap, and tuntap_defined().
int dco_get_peer_stats_multi | ( | dco_context_t * | dco, |
struct multi_context * | m, | ||
const bool | raise_sigusr1_on_err | ||
) |
const char * dco_get_supported_ciphers | ( | void | ) |
|
static |
Gets version of dco-win driver.
Fills Major/Minor/Patch fields in a passed OVPN_VERSION struct. If version cannot be obtained, fields are set to 0.
version | pointer to OVPN_VERSION struct |
Definition at line 73 of file dco_win.c.
References CLEAR, D_DCO_DEBUG, _OVPN_VERSION::Major, _OVPN_VERSION::Minor, msg, OVPN_IOCTL_GET_VERSION, and _OVPN_VERSION::Patch.
Referenced by dco_version_string(), and dco_win_supports_multipeer().
|
static |
Handles successful completion of overlapped operation.
We use overlapped I/O (Windows term for asynchronous I/O) to get notifications from kernel to userspace. This gets the result of overlapped operation and, in case of success, copies data from kernel-filled buffer into userspace-provided dco context.
dco | Pointer to the dco context |
queued | true if operation was queued, false if it has completed immediately |
Definition at line 655 of file dco_win.c.
References D_DCO_DEBUG, buffer::len, M_ERRNO, and msg.
Referenced by dco_do_read().
void dco_mp_start_vpn | ( | HANDLE | handle, |
struct link_socket * | sock | ||
) |
Initializes and binds the kernel UDP transport socket for multipeer mode.
Sends OVPN_IOCTL_MP_START_VPN
to create a kernel-mode UDP socket, binds it to the specified address, ready for incoming connections.
handle | Device handle for the DCO adapter. |
sock | Pointer to the link_socket structure containing socket information. |
Definition at line 280 of file dco_win.c.
References _OVPN_MP_START_VPN::Addr4, _OVPN_MP_START_VPN::Addr6, addr_family_name(), link_socket_info::bind_ipv6_only, link_socket_addr::bind_local, D_DCO_DEBUG, link_socket::info, _OVPN_MP_START_VPN::IPv6Only, _OVPN_MP_START_VPN::ListenAddress, link_socket_info::lsa, M_ERR, M_FATAL, msg, OVPN_IOCTL_MP_START_VPN, SF_PREPEND_SA, and link_socket::sockflags.
Referenced by create_socket_dco_win().
int dco_new_key | ( | dco_context_t * | dco, |
unsigned int | peerid, | ||
int | keyid, | ||
dco_key_slot_t | slot, | ||
const uint8_t * | encrypt_key, | ||
const uint8_t * | encrypt_iv, | ||
const uint8_t * | decrypt_key, | ||
const uint8_t * | decrypt_iv, | ||
const char * | ciphername | ||
) |
Definition at line 525 of file dco_win.c.
References ASSERT, cipher_kt_key_size(), _OVPN_CRYPTO_DATA::CipherAlg, D_DCO_DEBUG, _OVPN_CRYPTO_DATA::Decrypt, _OVPN_CRYPTO_DATA::Encrypt, _OVPN_KEY_DIRECTION::Key, _OVPN_CRYPTO_DATA::KeyId, _OVPN_KEY_DIRECTION::KeyLen, _OVPN_CRYPTO_DATA::KeySlot, M_ERR, msg, _OVPN_KEY_DIRECTION::NonceTail, OVPN_IOCTL_NEW_KEY, and _OVPN_CRYPTO_DATA::PeerId.
int dco_new_peer | ( | dco_context_t * | dco, |
unsigned int | peerid, | ||
int | sd, | ||
struct sockaddr * | localaddr, | ||
struct sockaddr * | remoteaddr, | ||
struct in_addr * | vpn_ipv4, | ||
struct in6_addr * | vpn_ipv6 | ||
) |
Definition at line 414 of file dco_win.c.
References _OVPN_MP_NEW_PEER::Addr4, _OVPN_MP_NEW_PEER::Addr6, D_DCO_DEBUG, _OVPN_MP_NEW_PEER::Local, M_ERR, msg, OVPN_IOCTL_MP_NEW_PEER, _OVPN_MP_NEW_PEER::PeerId, _OVPN_MP_NEW_PEER::Remote, _OVPN_MP_NEW_PEER::VpnAddr4, and _OVPN_MP_NEW_PEER::VpnAddr6.
void dco_p2p_new_peer | ( | HANDLE | handle, |
struct link_socket * | sock, | ||
struct signal_info * | sig_info | ||
) |
Definition at line 324 of file dco_win.c.
References _OVPN_NEW_PEER::Addr4, _OVPN_NEW_PEER::Addr6, addr_family_name(), ASSERT, link_socket_addr::bind_local, link_socket::bind_local, link_socket_addr::current_remote, D_DCO_DEBUG, dco_connect_wait(), get_server_poll_remaining_time(), link_socket::info, _OVPN_NEW_PEER::Local, link_socket_info::lsa, M_ERR, M_FATAL, msg, OVPN_IOCTL_NEW_PEER, OVPN_PROTO_TCP, OVPN_PROTO_UDP, _OVPN_NEW_PEER::Proto, _OVPN_NEW_PEER::Remote, and link_socket::server_poll_timeout.
Referenced by create_socket_dco_win().
void dco_p2p_start_vpn | ( | struct tuntap * | tt | ) |
Transitions the DCO adapter to the connected state in P2P mode.
Sends OVPN_IOCTL_START_VPN
to start the VPN and waits for the adapter to become ready.
tt | Pointer to the tuntap structure representing the adapter. |
Definition at line 166 of file dco_win.c.
References tuntap::adapter_index, dco_wait_ready(), tuntap::hand, M_ERR, msg, and OVPN_IOCTL_START_VPN.
Referenced by ovpn_dco_init().
int dco_set_peer | ( | dco_context_t * | dco, |
unsigned int | peerid, | ||
int | keepalive_interval, | ||
int | keepalive_timeout, | ||
int | mss | ||
) |
Definition at line 491 of file dco_win.c.
References D_DCO_DEBUG, M_ERRNO, M_WARN, msg, OVPN_IOCTL_MP_SET_PEER, OVPN_IOCTL_SET_PEER, and OVPN_SET_PEER.
int dco_swap_keys | ( | dco_context_t * | dco, |
unsigned int | peer_id | ||
) |
Definition at line 575 of file dco_win.c.
References D_DCO_DEBUG, M_ERR, msg, OVPN_IOCTL_MP_SWAP_KEYS, and OVPN_IOCTL_SWAP_KEYS.
const char * dco_version_string | ( | struct gc_arena * | gc | ) |
Definition at line 628 of file dco_win.c.
References alloc_buf_gc(), BSTR, buf_printf(), dco_get_version(), gc, and buffer::len.
|
static |
Definition at line 49 of file dco_win.c.
References D_DCO_DEBUG, and msg.
Referenced by dco_p2p_start_vpn(), and ovpn_dco_init_mp().
void dco_win_add_iroute_ipv4 | ( | dco_context_t * | dco, |
in_addr_t | dst, | ||
unsigned int | netbits, | ||
unsigned int | peer_id | ||
) |
Definition at line 828 of file dco_win.c.
References _OVPN_MP_IROUTE::Addr, _OVPN_MP_IROUTE::Addr4, D_DCO_DEBUG, gc, gc_free(), gc_new(), IA_NET_ORDER, M_ERRNO, M_WARN, msg, OVPN_IOCTL_MP_ADD_IROUTE, print_in_addr_t(), and route.
void dco_win_add_iroute_ipv6 | ( | dco_context_t * | dco, |
struct in6_addr | dst, | ||
unsigned int | netbits, | ||
unsigned int | peer_id | ||
) |
Definition at line 847 of file dco_win.c.
References _OVPN_MP_IROUTE::Addr, _OVPN_MP_IROUTE::Addr6, D_DCO_DEBUG, gc, gc_free(), gc_new(), IA_NET_ORDER, M_ERRNO, M_WARN, msg, OVPN_IOCTL_MP_ADD_IROUTE, print_in6_addr(), and route.
void dco_win_del_iroute_ipv4 | ( | dco_context_t * | dco, |
in_addr_t | dst, | ||
unsigned int | netbits | ||
) |
Definition at line 866 of file dco_win.c.
References _OVPN_MP_IROUTE::Addr, _OVPN_MP_IROUTE::Addr4, D_DCO_DEBUG, gc, gc_free(), gc_new(), IA_NET_ORDER, M_ERRNO, M_WARN, msg, OVPN_IOCTL_MP_DEL_IROUTE, print_in_addr_t(), and route.
void dco_win_del_iroute_ipv6 | ( | dco_context_t * | dco, |
struct in6_addr | dst, | ||
unsigned int | netbits | ||
) |
Definition at line 885 of file dco_win.c.
References _OVPN_MP_IROUTE::Addr, _OVPN_MP_IROUTE::Addr6, D_DCO_DEBUG, gc, gc_free(), gc_new(), IA_NET_ORDER, M_ERRNO, M_WARN, msg, OVPN_IOCTL_MP_DEL_IROUTE, print_in6_addr(), and route.
bool dco_win_supports_multipeer | ( | void | ) |
Definition at line 821 of file dco_win.c.
References dco_get_version(), and _OVPN_VERSION::Major.
int open_tun_dco | ( | struct tuntap * | tt, |
openvpn_net_ctx_t * | ctx, | ||
const char * | dev | ||
) |
bool ovpn_dco_init | ( | int | mode, |
dco_context_t * | dco, | ||
const char * | dev_node | ||
) |
Initializes DCO depends on mode
Definition at line 191 of file dco_win.c.
References ASSERT, dco_p2p_start_vpn(), MODE_POINT_TO_POINT, MODE_SERVER, and ovpn_dco_init_mp().
void ovpn_dco_init_mp | ( | dco_context_t * | dco, |
const char * | dev_node | ||
) |
Initializes the DCO adapter in multipeer mode and sets it to "connected" state.
Opens the DCO device, sets the adapter mode using OVPN_IOCTL_SET_MODE
, which transitions the adapter to the "connected" state, and waits for it to become ready.
dco | Pointer to the dco_context_t structure representing the DCO context. |
dev_node | Device node string for the DCO adapter. |
Definition at line 124 of file dco_win.c.
References ASSERT, dco_wait_ready(), gc, gc_free(), gc_new(), M_ERR, msg, OVPN_IOCTL_SET_MODE, OVPN_MODE_MP, and tun_open_device().
Referenced by ovpn_dco_init().