chore: apply dependency patches

This commit is contained in:
Sergey Abramchuk
2021-05-15 11:59:11 +03:00
parent d9eb2080b5
commit cb1a8fee43
8 changed files with 137 additions and 3 deletions

View File

@@ -953,6 +953,8 @@ public:
{
const protocol_type protocol = peer_endpoint.protocol();
impl_.get_service().open(impl_.get_implementation(), protocol, open_ec);
if (!open_ec)
async_connect_post_open(protocol, open_ec);
}
return async_initiate<ConnectHandler, void (asio::error_code)>(
@@ -1791,7 +1793,7 @@ protected:
* This function destroys the socket, cancelling any outstanding asynchronous
* operations associated with the socket as if by calling @c cancel.
*/
~basic_socket()
virtual ~basic_socket()
{
}
@@ -1807,6 +1809,11 @@ protected:
#endif
private:
// optional user code hook immediately after socket open in async_connect
virtual void async_connect_post_open(const protocol_type& protocol, asio::error_code& ec)
{
}
// Disallow copying and assignment.
basic_socket(const basic_socket&) ASIO_DELETED;
basic_socket& operator=(const basic_socket&) ASIO_DELETED;

View File

@@ -3339,6 +3339,23 @@ asio::error_code getaddrinfo(const char* host,
# endif
#elif !defined(ASIO_HAS_GETADDRINFO)
int error = getaddrinfo_emulation(host, service, &hints, result);
return ec = translate_addrinfo_error(error);
#elif defined(ASIO_HAS_GETADDRINFO) && defined(ASIO_APPLE_NAT64)
// For NAT64 compatibility, Apple recommends to set AI_DEFAULT flags
addrinfo_type new_hints = hints;
new_hints.ai_flags |= AI_DEFAULT;
int error = ::getaddrinfo(host, service, &new_hints, result);
// iOS bug workaround: sometimes iOS getaddrinfo() returns a non-zero scope ID
// for non-link-local addresses. Workaround by forcing scope ID to 0 for
// non-link-local addresses.
if (!error && (*result)->ai_family == AF_INET6)
{
sockaddr_in6* a6 = (sockaddr_in6*)(*result)->ai_addr;
if (a6->sin6_scope_id && !(IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&a6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&a6->sin6_addr)))
a6->sin6_scope_id = 0;
}
return ec = translate_addrinfo_error(error);
#else
int error = ::getaddrinfo(host, service, &hints, result);

View File

@@ -80,7 +80,7 @@ public:
DWORD length = ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, 0);
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (char*)&msg, 0, 0);
detail::local_free_on_block_exit local_free_obj(msg);
if (length && msg[length - 1] == '\n')
msg[--length] = '\0';

View File

@@ -186,6 +186,18 @@ public:
impl_.address(addr);
}
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
int get_route_id() const
{
return impl_.get_route_id();
}
void set_route_id(const int route_id)
{
impl_.set_route_id(route_id);
}
#endif
/// Compare two endpoints for equality.
friend bool operator==(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2) ASIO_NOEXCEPT

View File

@@ -18,6 +18,7 @@
#include "asio/detail/config.hpp"
#include <cstddef>
#include <cstring>
#include <algorithm>
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/ip/basic_resolver_iterator.hpp"
@@ -299,6 +300,20 @@ public:
return !a.equal(b);
}
#define HAVE_ASIO_RESOLVER_RESULTS_DATA
/// Return a pointer to the underlying results vector.
auto* data()
{
return this->values_.get();
}
/// Return a const pointer to the underlying results vector.
const auto* cdata() const
{
return this->values_.get();
}
private:
typedef std::vector<basic_resolver_entry<InternetProtocol> > values_type;
};

View File

@@ -24,6 +24,11 @@
#include "asio/detail/push_options.hpp"
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
#include <cstdint>
#include <uapi/ovpn/mark.h>
#endif
namespace asio {
namespace ip {
namespace detail {
@@ -118,6 +123,47 @@ public:
ASIO_DECL std::string to_string() const;
#endif // !defined(ASIO_NO_IOSTREAM)
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
int get_route_id() const
{
if (is_v4())
{
if (data_.v4_sin_ovpn_magic == SIN_OVPN_MAGIC)
return OVPN_MARK_ROUTE_ID(data_.v4_sin_ovpn_route_id);
}
else
{
if ((data_.v6.sin6_flowinfo & htonl(SIN6_FLOWINFO_OVPN_MASK)) == htonl(SIN6_FLOWINFO_OVPN_MAGIC))
return OVPN_MARK_ROUTE_ID(ntohl(data_.v6.sin6_flowinfo));
}
return -1;
}
void set_route_id(const int route_id)
{
if (is_v4())
{
if (route_id >= 0)
{
data_.v4_sin_ovpn_magic = SIN_OVPN_MAGIC;
data_.v4_sin_ovpn_route_id = OVPN_MARK_ROUTE_ID(route_id);
}
else
{
data_.v4_sin_ovpn_magic = 0;
data_.v4_sin_ovpn_route_id = 0;
}
}
else
{
if (route_id >= 0)
data_.v6.sin6_flowinfo = htonl(OVPN_MARK_ROUTE_ID(route_id) | SIN6_FLOWINFO_OVPN_MAGIC);
else
data_.v6.sin6_flowinfo = 0;
}
}
#endif
private:
// The underlying IP socket address.
union data_union
@@ -125,6 +171,15 @@ private:
asio::detail::socket_addr_type base;
asio::detail::sockaddr_in4_type v4;
asio::detail::sockaddr_in6_type v6;
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
struct {
std::uint8_t head_[8];
// mirrors definition in <linux-kernel>/include/uapi/linux/in.h
std::uint32_t v4_sin_ovpn_magic;
std::uint32_t v4_sin_ovpn_route_id;
};
#endif
} data_;
};

View File

@@ -37,6 +37,10 @@ endpoint::endpoint() ASIO_NOEXCEPT
data_.v4.sin_family = ASIO_OS_DEF(AF_INET);
data_.v4.sin_port = 0;
data_.v4.sin_addr.s_addr = ASIO_OS_DEF(INADDR_ANY);
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
data_.v4_sin_ovpn_magic = 0;
data_.v4_sin_ovpn_route_id = 0;
#endif
}
endpoint::endpoint(int family, unsigned short port_num) ASIO_NOEXCEPT
@@ -49,6 +53,10 @@ endpoint::endpoint(int family, unsigned short port_num) ASIO_NOEXCEPT
data_.v4.sin_port =
asio::detail::socket_ops::host_to_network_short(port_num);
data_.v4.sin_addr.s_addr = ASIO_OS_DEF(INADDR_ANY);
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
data_.v4_sin_ovpn_magic = 0;
data_.v4_sin_ovpn_route_id = 0;
#endif
}
else
{
@@ -81,6 +89,10 @@ endpoint::endpoint(const asio::ip::address& addr,
data_.v4.sin_addr.s_addr =
asio::detail::socket_ops::host_to_network_long(
addr.to_v4().to_uint());
#if defined(ASIO_USE_KOVPN_ROUTE_ID)
data_.v4_sin_ovpn_magic = 0;
data_.v4_sin_ovpn_route_id = 0;
#endif
}
else
{

View File

@@ -564,13 +564,20 @@ static int x509_parse_time( unsigned char **p, size_t len, size_t yearlen,
/*
* Parse seconds if present
*/
if ( len >= 2 )
if ( len >= 2 && **p >= '0' && **p <= '9' )
{
CHECK( x509_parse_int( p, 2, &tm->sec ) );
len -= 2;
}
else
{
#if defined(MBEDTLS_RELAXED_X509_DATE)
/* if relaxed mode, allow seconds to be absent */
tm->sec = 0;
#else
return ( MBEDTLS_ERR_X509_INVALID_DATE );
#endif
}
/*
* Parse trailing 'Z' if present
@@ -580,6 +587,15 @@ static int x509_parse_time( unsigned char **p, size_t len, size_t yearlen,
(*p)++;
len--;
}
#if defined(MBEDTLS_RELAXED_X509_DATE)
else if ( len == 5 && **p == '+' )
{
int tz; /* throwaway timezone */
(*p)++;
CHECK( x509_parse_int( p, 4, &tz ) );
return 0;
}
#endif
/*
* We should have parsed all characters at this point