return;
#endif
- if (flags & M_ERRNO_SOCK)
- e = openvpn_errno_socket ();
- else
- e = openvpn_errno ();
+ e = openvpn_errno ();
/*
* Apply muting filter.
va_end (arglist);
m1[ERR_BUF_SIZE - 1] = 0; /* windows vsnprintf needs this */
- if ((flags & (M_ERRNO|M_ERRNO_SOCK)) && e)
+ if ((flags & M_ERRNO) && e)
{
openvpn_snprintf (m2, ERR_BUF_SIZE, "%s: %s (errno=%d)",
m1, strerror_ts (e, &gc), e);
struct link_socket *sock,
struct tuntap *tt)
{
- const int my_errno = (sock ? openvpn_errno_socket () : (int)openvpn_errno ());
+ const int my_errno = openvpn_errno ();
const char *extended_msg = NULL;
msg (x_cs_verbose_level, "%s %s returned %d",
#ifdef WIN32
# define openvpn_errno() GetLastError()
-# define openvpn_errno_socket() WSAGetLastError()
# define openvpn_strerror(e, gc) strerror_win32(e, gc)
const char *strerror_win32 (DWORD errnum, struct gc_arena *gc);
#else
# define openvpn_errno() errno
-# define openvpn_errno_socket() errno
# define openvpn_strerror(x, gc) strerror(x)
#endif
#define M_DEBUG (1<<7)
#define M_ERRNO (1<<8) /* show errno description */
-#define M_ERRNO_SOCK (1<<9) /* show socket errno description */
#ifdef ENABLE_CRYPTO_OPENSSL
# define M_SSL (1<<10) /* show SSL error */
/* flag combinations which are frequently used */
#define M_ERR (M_FATAL | M_ERRNO)
-#define M_SOCKERR (M_FATAL | M_ERRNO_SOCK)
#define M_SSLERR (M_FATAL | M_SSL)
#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)
#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)
set_nonblock (int fd)
{
if (!set_nonblock_action (fd))
- msg (M_SOCKERR, "Set socket to non-blocking mode failed");
+ msg (M_ERR, "Set socket to non-blocking mode failed");
}
/* Set a file descriptor to not be passed across execs */
* Listen for connection
*/
if (listen (man->connection.sd_top, 1))
- msg (M_SOCKERR, "MANAGEMENT: listen() failed");
+ msg (M_ERR, "MANAGEMENT: listen() failed");
/*
* Set misc socket properties
static bool
man_io_error (struct management *man, const char *prefix)
{
- const int err = openvpn_errno_socket ();
+ const int err = openvpn_errno ();
if (!ignore_sys_error (err))
{
if (status == 0)
{
if (verbose)
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: TCP port read timeout expired");
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_line: TCP port read timeout expired");
goto error;
}
if (status < 0)
{
if (verbose)
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: TCP port read failed on select()");
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_line: TCP port read failed on select()");
goto error;
}
if (size != 1)
{
if (verbose)
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: TCP port read failed on recv()");
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_line: TCP port read failed on recv()");
goto error;
}
if (!isprint(c) && !isspace(c)) /* not ascii? */
{
if (verbose)
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_line: Non-ASCII character (%d) read on recv()", (int)c);
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_line: Non-ASCII character (%d) read on recv()", (int)c);
*lookahead = la;
return false;
}
const ssize_t size = send (sd, buf, strlen (buf), MSG_NOSIGNAL);
if (size != (ssize_t) strlen (buf))
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "send_line: TCP port write failed on send()");
+ msg (D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()");
return false;
}
return true;
status = sendmsg (sd, &mesg, MSG_NOSIGNAL);
if (status == -1)
- msg (M_WARN|M_ERRNO_SOCK, "PORT SHARE: sendmsg failed -- unable to communicate with background process (%d,%d,%d,%d)",
+ msg (M_WARN|M_ERRNO, "PORT SHARE: sendmsg failed -- unable to communicate with background process (%d,%d,%d,%d)",
sd, sd_send, sd_null[0], sd_null[1]
);
sock_addr_set (&osaddr, server_addr, server_port);
if ((sd_server = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
- msg (M_WARN|M_ERRNO_SOCK, "PORT SHARE PROXY: cannot create socket");
+ msg (M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket");
return false;
}
status = openvpn_connect (sd_server, &osaddr, 5, NULL);
}
else
{
- msg (M_SOCKERR, "PORT SHARE: unexpected init recv_control status=%d", status);
+ msg (M_ERR, "PORT SHARE: unexpected init recv_control status=%d", status);
}
}
else
socket_descriptor_t sd;
if ((sd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
- msg (M_SOCKERR, "Cannot create TCP socket");
+ msg (M_ERR, "Cannot create TCP socket");
#ifndef WIN32 /* using SO_REUSEADDR on Windows will cause bind to succeed on port conflicts! */
/* set SO_REUSEADDR on socket */
int on = 1;
if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR,
(void *) &on, sizeof (on)) < 0)
- msg (M_SOCKERR, "TCP: Cannot setsockopt SO_REUSEADDR on TCP socket");
+ msg (M_ERR, "TCP: Cannot setsockopt SO_REUSEADDR on TCP socket");
}
#endif
linger.l_linger = 2;
if (setsockopt (sd, SOL_SOCKET, SO_LINGER,
(void *) &linger, sizeof (linger)) < 0)
- msg (M_SOCKERR, "TCP: Cannot setsockopt SO_LINGER on TCP socket");
+ msg (M_ERR, "TCP: Cannot setsockopt SO_LINGER on TCP socket");
}
#endif
socket_descriptor_t sd;
if ((sd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
- msg (M_SOCKERR, "UDP: Cannot create UDP socket");
+ msg (M_ERR, "UDP: Cannot create UDP socket");
#if ENABLE_IP_PKTINFO
else if (flags & SF_USE_IP_PKTINFO)
{
#ifdef IP_PKTINFO
if (setsockopt (sd, SOL_IP, IP_PKTINFO,
(void*)&pad, sizeof(pad)) < 0)
- msg(M_SOCKERR, "UDP: failed setsockopt for IP_PKTINFO");
+ msg(M_ERR, "UDP: failed setsockopt for IP_PKTINFO");
#elif defined(IP_RECVDSTADDR)
if (setsockopt (sd, IPPROTO_IP, IP_RECVDSTADDR,
(void*)&pad, sizeof(pad)) < 0)
- msg(M_SOCKERR, "UDP: failed setsockopt for IP_RECVDSTADDR");
+ msg(M_ERR, "UDP: failed setsockopt for IP_RECVDSTADDR");
#else
#error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
#endif
socket_descriptor_t sd;
if ((sd = socket (PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0)
- msg (M_SOCKERR, "UDP: Cannot create UDP6 socket");
+ msg (M_ERR, "UDP: Cannot create UDP6 socket");
#if ENABLE_IP_PKTINFO
else if (flags & SF_USE_IP_PKTINFO)
{
if (setsockopt (sd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
(void*)&pad, sizeof(pad)) < 0)
#endif
- msg(M_SOCKERR, "UDP: failed setsockopt for IPV6_RECVPKTINFO");
+ msg(M_ERR, "UDP: failed setsockopt for IPV6_RECVPKTINFO");
}
#endif
return sd;
socket_descriptor_t sd;
if ((sd = socket (PF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0)
- msg (M_SOCKERR, "Cannot create TCP6 socket");
+ msg (M_ERR, "Cannot create TCP6 socket");
/* set SO_REUSEADDR on socket */
{
int on = 1;
if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR,
(void *) &on, sizeof (on)) < 0)
- msg (M_SOCKERR, "TCP: Cannot setsockopt SO_REUSEADDR on TCP6 socket");
+ msg (M_ERR, "TCP: Cannot setsockopt SO_REUSEADDR on TCP6 socket");
}
return sd;
msg (M_INFO, "Listening for incoming TCP connection on %s",
print_sockaddr (local, &gc));
if (listen (sd, 1))
- msg (M_SOCKERR, "TCP: listen() failed");
+ msg (M_ERR, "TCP: listen() failed");
}
/* set socket to non-blocking mode */
new_sd = getpeername (sd, &act->dest.addr.sa, &remote_len);
if (!socket_defined (new_sd))
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "TCP: getpeername() failed");
+ msg (D_LINK_ERRORS | M_ERRNO, "TCP: getpeername() failed");
else
new_sd = sd;
}
if (!socket_defined (new_sd))
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "TCP: accept(%d) failed", sd);
+ msg (D_LINK_ERRORS | M_ERRNO, "TCP: accept(%d) failed", sd);
}
/* only valid if we have remote_len_af!=0 */
else if (remote_len_af && remote_len != remote_len_af)
}
if (status < 0)
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "TCP: select() failed");
+ msg (D_LINK_ERRORS | M_ERRNO, "TCP: select() failed");
if (status <= 0)
{
"TCP NOTE: Rejected connection attempt from %s due to --remote setting",
print_link_socket_actual (act, &gc));
if (openvpn_close_socket (new_sd))
- msg (M_SOCKERR, "TCP: close socket failed (new_sd)");
+ msg (M_ERR, "TCP: close socket failed (new_sd)");
}
else
break;
}
if (!nowait && openvpn_close_socket (sd))
- msg (M_SOCKERR, "TCP: close socket failed (sd)");
+ msg (M_ERR, "TCP: close socket failed (sd)");
tcp_connection_established (act);
if (bind (sd, &local->addr.sa, af_addr_size(local->addr.sa.sa_family)))
{
- const int errnum = openvpn_errno_socket ();
+ const int errnum = openvpn_errno ();
msg (M_FATAL, "%s: Socket bind failed on local address %s: %s",
prefix,
print_sockaddr (local, &gc),
set_nonblock (sd);
status = connect (sd, &remote->addr.sa, af_addr_size(remote->addr.sa.sa_family));
if (status)
- status = openvpn_errno_socket ();
+ status = openvpn_errno ();
if (
#ifdef WIN32
status == WSAEWOULDBLOCK
}
if (status < 0)
{
- status = openvpn_errno_socket ();
+ status = openvpn_errno ();
break;
}
if (status <= 0)
&& len == sizeof (val))
status = val;
else
- status = openvpn_errno_socket ();
+ status = openvpn_errno ();
break;
}
}
#else
status = connect (sd, &remote->addr.sa, af_addr_size(remote->addr.sa.sa_family));
if (status)
- status = openvpn_errno_socket ();
+ status = openvpn_errno ();
#endif
return status;
{
msg (D_LOW, "TCP/UDP: Closing socket");
if (openvpn_close_socket (sock->sd))
- msg (M_WARN | M_ERRNO_SOCK, "TCP/UDP: Close Socket failed");
+ msg (M_WARN | M_ERRNO, "TCP/UDP: Close Socket failed");
}
sock->sd = SOCKET_UNDEFINED;
#ifdef WIN32
if (socket_defined (sock->ctrl_sd))
{
if (openvpn_close_socket (sock->ctrl_sd))
- msg (M_WARN | M_ERRNO_SOCK, "TCP/UDP: Close Socket (ctrl_sd) failed");
+ msg (M_WARN | M_ERRNO, "TCP/UDP: Close Socket (ctrl_sd) failed");
sock->ctrl_sd = SOCKET_UNDEFINED;
}
#endif
/* if no error (i.e. just not finished yet), then DON'T execute this code */
io->iostate = IOSTATE_INITIAL;
ASSERT (ResetEvent (io->overlapped.hEvent));
- msg (D_WIN32_IO | M_ERRNO_SOCK, "WIN32 I/O: Socket Completion error");
+ msg (D_WIN32_IO | M_ERRNO, "WIN32 I/O: Socket Completion error");
}
}
break;
/* error return for a non-queued operation */
WSASetLastError (io->status);
ret = -1;
- msg (D_WIN32_IO | M_ERRNO_SOCK, "WIN32 I/O: Socket Completion non-queued error");
+ msg (D_WIN32_IO | M_ERRNO, "WIN32 I/O: Socket Completion non-queued error");
}
else
{
socket_descriptor_t sd;
if ((sd = socket (PF_UNIX, SOCK_STREAM, 0)) < 0)
- msg (M_SOCKERR, "Cannot create unix domain socket");
+ msg (M_ERR, "Cannot create unix domain socket");
return sd;
}
if (bind (sd, (struct sockaddr *) local, sizeof (struct sockaddr_un)))
{
- const int errnum = openvpn_errno_socket ();
+ const int errnum = openvpn_errno ();
msg (M_FATAL, "%s: Socket bind[%d] failed on unix domain socket %s: %s",
prefix,
(int)sd,
{
int status = connect (sd, (struct sockaddr *) remote, sizeof (struct sockaddr_un));
if (status)
- status = openvpn_errno_socket ();
+ status = openvpn_errno ();
return status;
}
return true;
else if (status < 0)
{
- const int err = openvpn_errno_socket ();
+ const int err = openvpn_errno ();
#ifdef WIN32
return err == WSAECONNRESET || err == WSAECONNABORTED;
#else
if (size != strlen (to_send))
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_username_password_auth: TCP port write failed on send()");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP port write failed on send()");
return false;
}
/* timeout? */
if (status == 0)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_username_password_auth: TCP port read timeout expired");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP port read timeout expired");
return false;
}
/* error */
if (status < 0)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_username_password_auth: TCP port read failed on select()");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP port read failed on select()");
return false;
}
/* error? */
if (size != 1)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_username_password_auth: TCP port read failed on recv()");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP port read failed on recv()");
return false;
}
const ssize_t size = send (sd, "\x05\x02\x00\x02", 4, MSG_NOSIGNAL);
if (size != 4)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_handshake: TCP port write failed on send()");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()");
return false;
}
/* timeout? */
if (status == 0)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_handshake: TCP port read timeout expired");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read timeout expired");
return false;
}
/* error */
if (status < 0)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_handshake: TCP port read failed on select()");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read failed on select()");
return false;
}
/* error? */
if (size != 1)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "socks_handshake: TCP port read failed on recv()");
+ msg (D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read failed on recv()");
return false;
}
/* timeout? */
if (status == 0)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_socks_reply: TCP port read timeout expired");
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read timeout expired");
return false;
}
/* error */
if (status < 0)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_socks_reply: TCP port read failed on select()");
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read failed on select()");
return false;
}
/* error? */
if (size != 1)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "recv_socks_reply: TCP port read failed on recv()");
+ msg (D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read failed on recv()");
return false;
}
const ssize_t size = send (sd, buf, 5 + len + 2, MSG_NOSIGNAL);
if ((int)size != 5 + (int)len + 2)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "establish_socks_proxy_passthru: TCP port write failed on send()");
+ msg (D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru: TCP port write failed on send()");
goto error;
}
}
10, MSG_NOSIGNAL);
if (size != 10)
{
- msg (D_LINK_ERRORS | M_ERRNO_SOCK, "establish_socks_proxy_passthru: TCP port write failed on send()");
+ msg (D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru: TCP port write failed on send()");
goto error;
}
}
/* setup network events to change read event state */
if (WSAEventSelect (sd, event->read, network_events) != 0)
- msg (M_FATAL | M_ERRNO_SOCK, "Error: init_net_event_win32: WSAEventSelect call failed");
+ msg (M_FATAL | M_ERRNO, "Error: init_net_event_win32: WSAEventSelect call failed");
}
long
WSANETWORKEVENTS wne;
if (WSAEnumNetworkEvents (sd, event->read, &wne) != 0)
{
- msg (M_FATAL | M_ERRNO_SOCK, "Error: reset_net_event_win32: WSAEnumNetworkEvents call failed");
+ msg (M_FATAL | M_ERRNO, "Error: reset_net_event_win32: WSAEnumNetworkEvents call failed");
return 0; /* NOTREACHED */
}
else
if (socket_defined (sd))
{
if (WSAEventSelect (sd, event->read, 0) != 0)
- msg (M_WARN | M_ERRNO_SOCK, "Warning: close_net_event_win32: WSAEventSelect call failed");
+ msg (M_WARN | M_ERRNO, "Warning: close_net_event_win32: WSAEventSelect call failed");
}
if (!ResetEvent (event->read))
msg (M_WARN | M_ERRNO, "Warning: ResetEvent (read) failed in close_net_event_win32");