mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 04:02:15 +02:00
Implement error handling if socket_protect() call fails.
This commit is contained in:
parent
da248a8fbd
commit
9f5cfc465a
@ -81,6 +81,16 @@ namespace openvpn {
|
||||
throw exc(_ovpn_exc.str()); \
|
||||
} while (0)
|
||||
|
||||
// properly rethrow an exception that might be derived from Exception
|
||||
inline void throw_ref(const std::exception& e)
|
||||
{
|
||||
const Exception* ex = dynamic_cast<const Exception*>(&e);
|
||||
if (ex)
|
||||
throw *ex;
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
|
||||
} // namespace openvpn
|
||||
|
||||
#endif // OPENVPN_COMMON_EXCEPTION_H
|
||||
|
@ -15,6 +15,7 @@ namespace openvpn {
|
||||
BAD_SRC_ADDR, // packet from unknown source address
|
||||
COMPRESS_ERROR, // compress/decompress errors on data channel
|
||||
RESOLVE_ERROR, // DNS resolution error
|
||||
SOCKET_PROTECT_ERROR, // Error calling protect() method on socket
|
||||
TUN_ERROR, // errors on tun/tap interface
|
||||
TCP_OVERFLOW, // TCP output queue overflow
|
||||
TCP_SIZE_ERROR, // bad embedded uint16_t TCP packet size
|
||||
@ -42,6 +43,7 @@ namespace openvpn {
|
||||
"BAD_SRC_ADDR",
|
||||
"COMPRESS_ERROR",
|
||||
"RESOLVE_ERROR",
|
||||
"SOCKET_PROTECT_ERROR",
|
||||
"TUN_ERROR",
|
||||
"TCP_OVERFLOW",
|
||||
"TCP_SIZE_ERROR",
|
||||
|
@ -15,6 +15,7 @@ namespace openvpn {
|
||||
|
||||
OPENVPN_EXCEPTION(tcp_transport_resolve_error);
|
||||
OPENVPN_EXCEPTION(tcp_transport_error);
|
||||
OPENVPN_SIMPLE_EXCEPTION(tcp_transport_socket_protect_error);
|
||||
|
||||
class ClientConfig : public TransportClientFactory
|
||||
{
|
||||
@ -145,7 +146,7 @@ namespace openvpn {
|
||||
parent.transport_recv(buf);
|
||||
}
|
||||
|
||||
void tcp_error_handler(const char *error)
|
||||
void tcp_error_handler(const char *error) // called by LinkImpl
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Transport error on '" << config->server_host << ": " << error;
|
||||
@ -197,7 +198,16 @@ namespace openvpn {
|
||||
socket.open(server_endpoint.protocol());
|
||||
#ifdef OPENVPN_PLATFORM_TYPE_UNIX
|
||||
if (config->socket_protect)
|
||||
config->socket_protect->socket_protect(socket.native_handle());
|
||||
{
|
||||
if (!config->socket_protect->socket_protect(socket.native_handle()))
|
||||
{
|
||||
config->stats->error(Error::SOCKET_PROTECT_ERROR);
|
||||
stop();
|
||||
tcp_transport_socket_protect_error err;
|
||||
parent.transport_error(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
socket.set_option(boost::asio::ip::tcp::no_delay(true));
|
||||
socket.async_connect(server_endpoint, asio_dispatch_connect(&Client::start_impl_, this));
|
||||
|
@ -14,6 +14,7 @@ namespace openvpn {
|
||||
namespace UDPTransport {
|
||||
|
||||
OPENVPN_EXCEPTION(udp_transport_resolve_error);
|
||||
OPENVPN_SIMPLE_EXCEPTION(udp_transport_socket_protect_error);
|
||||
|
||||
class ClientConfig : public TransportClientFactory
|
||||
{
|
||||
@ -178,7 +179,16 @@ namespace openvpn {
|
||||
socket.open(server_endpoint.protocol());
|
||||
#ifdef OPENVPN_PLATFORM_TYPE_UNIX
|
||||
if (config->socket_protect)
|
||||
config->socket_protect->socket_protect(socket.native_handle());
|
||||
{
|
||||
if (!config->socket_protect->socket_protect(socket.native_handle()))
|
||||
{
|
||||
config->stats->error(Error::SOCKET_PROTECT_ERROR);
|
||||
stop();
|
||||
udp_transport_socket_protect_error err;
|
||||
parent.transport_error(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
socket.connect(server_endpoint);
|
||||
impl.reset(new LinkImpl(this,
|
||||
|
Loading…
Reference in New Issue
Block a user