77 std::ostringstream os;
87 if (
tun_persist->persist_tun_state(ts, {state, ring_buffer}))
88 OPENVPN_LOG(
"TunPersist: saving tun context:" << std::endl
103 catch (
const std::exception &e)
132 ULONG head = receive_ring->
head.load(std::memory_order_acquire);
135 if (head == 0xFFFFFFFF)
140 ULONG tail = receive_ring->
tail.load(std::memory_order_acquire);
146 if (aligned_packet_size > buf_space)
156 packet->
size =
static_cast<decltype(packet-
>size)>(
buf.
size());
160 receive_ring->
tail.store(
wrap(tail +
static_cast<ULONG
>(aligned_packet_size)), std::memory_order_release);
161 if (receive_ring->
alertable.load(std::memory_order_acquire) != 0)
174 if (
state->vpn_ip4_addr.specified())
175 return state->vpn_ip4_addr.to_string();
182 if (
state->vpn_ip6_addr.specified())
183 return state->vpn_ip6_addr.to_string();
190 if (
state->vpn_ip4_gw.specified())
191 return state->vpn_ip4_gw.to_string();
198 if (
state->vpn_ip6_gw.specified())
199 return state->vpn_ip6_gw.to_string();
217 ULONG head = send_ring->
head.load(std::memory_order_acquire);
224 ULONG tail = send_ring->
tail.load(std::memory_order_acquire);
236 ring_buffer->send_tail_moved_asio_event().async_wait([self =
Ptr(
this)](
const openvpn_io::error_code &error)
243 self->parent.tun_error(
Error::TUN_ERROR,
"error waiting on ring send tail moved");
249 ULONG content_len =
wrap(tail - head);
264 if (aligned_packet_size > content_len)
274 head =
wrap(head +
static_cast<ULONG
>(aligned_packet_size));
275 send_ring->
head.store(head, std::memory_order_release);
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
void write(const T *data, const size_t size)
Write data to the buffer.
bool code_defined() const
size_t prepare(const unsigned int context, Buffer &buf) const
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
T * get() const noexcept
Returns the raw pointer to the object T, or nullptr.
std::string to_string() const
static void configure_builder(TunBuilderBase *tb, State *state, SessionStats *stats, const IP::Addr &server_addr, const Config &config, const OptionList &opt, const EmulateExcludeRouteFactory *eer_factory, const bool quiet)
WintunClient(openvpn_io::io_context &io_context_arg, ClientConfig *config_arg, TunClientParent &parent_arg)
int vpn_mtu() const override
ScopedHANDLE driver_handle
TunWin::SetupBase::Ptr tun_setup
openvpn_io::io_context & io_context
std::string tun_name() const override
void set_disconnect() override
std::string vpn_ip6() const override
RingBuffer::Ptr ring_buffer
std::string vpn_gw6() const override
bool tun_send(BufferAllocated &buf) override
RCPtr< WintunClient > Ptr
std::string vpn_ip4() const override
size_t packet_align(size_t size)
std::string vpn_gw4() const override
void tun_start(const OptionList &opt, TransportClient &transcli, CryptoDCSettings &) override
TunProp::State::Ptr state
TunPersist::Ptr tun_persist
#define OPENVPN_LOG(args)
#define OPENVPN_LOG_STRING(str)
DNS utilities for Windows.
openvpn_io::windows::stream_handle TAPStream
TunPersistTemplate< ScopedTAPStream, TunPersistState< RingBuffer::Ptr > > TunPersist
std::wstring module_name()
bool is_safe_conversion(InT inVal)
Returns true if the given value can be contained by the out type.
CleanupType< F > Cleanup(F method) noexcept
#define WINTUN_PACKET_ALIGN
#define WINTUN_MAX_PACKET_SIZE
#define WINTUN_RING_CAPACITY
virtual IP::Addr server_endpoint_addr() const =0
virtual void tun_error(const Error::Type fatal_err, const std::string &err_text)=0
virtual void tun_connected()=0
virtual void tun_pre_tun_config()=0
virtual void tun_recv(BufferAllocated &buf)=0
std::atomic_long alertable
UCHAR data[WINTUN_RING_CAPACITY+WINTUN_RING_TRAILING_BYTES+WINTUN_RING_FRAMING_SIZE]
UCHAR data[WINTUN_MAX_PACKET_SIZE]