mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
socket-util: Move sock_errno() to socket-util.
And add more users. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
@@ -106,7 +106,7 @@ set_dscp(int fd, uint8_t dscp)
|
|||||||
|
|
||||||
val = dscp << 2;
|
val = dscp << 2;
|
||||||
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &val, sizeof val)) {
|
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &val, sizeof val)) {
|
||||||
return errno;
|
return sock_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -239,7 +239,7 @@ lookup_hostname(const char *host_name, struct in_addr *addr)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
case EAI_SYSTEM:
|
case EAI_SYSTEM:
|
||||||
return errno;
|
return sock_errno();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return EPROTO;
|
return EPROTO;
|
||||||
@@ -762,8 +762,8 @@ inet_open_active(int style, const char *target, uint16_t default_port,
|
|||||||
/* Create non-blocking socket. */
|
/* Create non-blocking socket. */
|
||||||
fd = socket(ss.ss_family, style, 0);
|
fd = socket(ss.ss_family, style, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
VLOG_ERR("%s: socket: %s", target, ovs_strerror(errno));
|
error = sock_errno();
|
||||||
error = errno;
|
VLOG_ERR("%s: socket: %s", target, sock_strerror(error));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
error = set_nonblocking(fd);
|
error = set_nonblocking(fd);
|
||||||
@@ -776,15 +776,19 @@ inet_open_active(int style, const char *target, uint16_t default_port,
|
|||||||
* connect(), the handshake SYN frames will be sent with a TOS of 0. */
|
* connect(), the handshake SYN frames will be sent with a TOS of 0. */
|
||||||
error = set_dscp(fd, dscp);
|
error = set_dscp(fd, dscp);
|
||||||
if (error) {
|
if (error) {
|
||||||
VLOG_ERR("%s: socket: %s", target, ovs_strerror(error));
|
VLOG_ERR("%s: socket: %s", target, sock_strerror(error));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connect. */
|
/* Connect. */
|
||||||
error = connect(fd, (struct sockaddr *) &ss, ss_length(&ss)) == 0
|
error = connect(fd, (struct sockaddr *) &ss, ss_length(&ss)) == 0
|
||||||
? 0
|
? 0
|
||||||
: errno;
|
: sock_errno();
|
||||||
if (error == EINPROGRESS) {
|
if (error == EINPROGRESS
|
||||||
|
#ifdef _WIN32
|
||||||
|
|| error == WSAEALREADY || error == WSAEWOULDBLOCK
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
error = EAGAIN;
|
error = EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,8 +885,8 @@ inet_open_passive(int style, const char *target, int default_port,
|
|||||||
/* Create non-blocking socket, set SO_REUSEADDR. */
|
/* Create non-blocking socket, set SO_REUSEADDR. */
|
||||||
fd = socket(ss.ss_family, style, 0);
|
fd = socket(ss.ss_family, style, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
error = errno;
|
error = sock_errno();
|
||||||
VLOG_ERR("%s: socket: %s", target, ovs_strerror(error));
|
VLOG_ERR("%s: socket: %s", target, sock_strerror(error));
|
||||||
return -error;
|
return -error;
|
||||||
}
|
}
|
||||||
error = set_nonblocking(fd);
|
error = set_nonblocking(fd);
|
||||||
@@ -891,16 +895,16 @@ inet_open_passive(int style, const char *target, int default_port,
|
|||||||
}
|
}
|
||||||
if (style == SOCK_STREAM
|
if (style == SOCK_STREAM
|
||||||
&& setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) < 0) {
|
&& setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) < 0) {
|
||||||
error = errno;
|
error = sock_errno();
|
||||||
VLOG_ERR("%s: setsockopt(SO_REUSEADDR): %s",
|
VLOG_ERR("%s: setsockopt(SO_REUSEADDR): %s",
|
||||||
target, ovs_strerror(error));
|
target, sock_strerror(error));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bind. */
|
/* Bind. */
|
||||||
if (bind(fd, (struct sockaddr *) &ss, ss_length(&ss)) < 0) {
|
if (bind(fd, (struct sockaddr *) &ss, ss_length(&ss)) < 0) {
|
||||||
error = errno;
|
error = sock_errno();
|
||||||
VLOG_ERR("%s: bind: %s", target, ovs_strerror(error));
|
VLOG_ERR("%s: bind: %s", target, sock_strerror(error));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,22 +913,22 @@ inet_open_passive(int style, const char *target, int default_port,
|
|||||||
* connect(), the handshake SYN frames will be sent with a TOS of 0. */
|
* connect(), the handshake SYN frames will be sent with a TOS of 0. */
|
||||||
error = set_dscp(fd, dscp);
|
error = set_dscp(fd, dscp);
|
||||||
if (error) {
|
if (error) {
|
||||||
VLOG_ERR("%s: socket: %s", target, ovs_strerror(error));
|
VLOG_ERR("%s: socket: %s", target, sock_strerror(error));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Listen. */
|
/* Listen. */
|
||||||
if (style == SOCK_STREAM && listen(fd, 10) < 0) {
|
if (style == SOCK_STREAM && listen(fd, 10) < 0) {
|
||||||
error = errno;
|
error = sock_errno();
|
||||||
VLOG_ERR("%s: listen: %s", target, ovs_strerror(error));
|
VLOG_ERR("%s: listen: %s", target, sock_strerror(error));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ssp || kernel_chooses_port) {
|
if (ssp || kernel_chooses_port) {
|
||||||
socklen_t ss_len = sizeof ss;
|
socklen_t ss_len = sizeof ss;
|
||||||
if (getsockname(fd, (struct sockaddr *) &ss, &ss_len) < 0) {
|
if (getsockname(fd, (struct sockaddr *) &ss, &ss_len) < 0) {
|
||||||
error = errno;
|
error = sock_errno();
|
||||||
VLOG_ERR("%s: getsockname: %s", target, ovs_strerror(error));
|
VLOG_ERR("%s: getsockname: %s", target, sock_strerror(error));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (kernel_chooses_port) {
|
if (kernel_chooses_port) {
|
||||||
@@ -1095,8 +1099,8 @@ getsockopt_int(int fd, int level, int option, const char *optname, int *valuep)
|
|||||||
|
|
||||||
len = sizeof value;
|
len = sizeof value;
|
||||||
if (getsockopt(fd, level, option, &value, &len)) {
|
if (getsockopt(fd, level, option, &value, &len)) {
|
||||||
error = errno;
|
error = sock_errno();
|
||||||
VLOG_ERR_RL(&rl, "getsockopt(%s): %s", optname, ovs_strerror(error));
|
VLOG_ERR_RL(&rl, "getsockopt(%s): %s", optname, sock_strerror(error));
|
||||||
} else if (len != sizeof value) {
|
} else if (len != sizeof value) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
VLOG_ERR_RL(&rl, "getsockopt(%s): value is %u bytes (expected %"PRIuSIZE")",
|
VLOG_ERR_RL(&rl, "getsockopt(%s): value is %u bytes (expected %"PRIuSIZE")",
|
||||||
@@ -1256,8 +1260,9 @@ af_inet_ioctl(unsigned long int command, const void *arg)
|
|||||||
if (ovsthread_once_start(&once)) {
|
if (ovsthread_once_start(&once)) {
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
sock = -errno;
|
int error = sock_errno();
|
||||||
VLOG_ERR("failed to create inet socket: %s", ovs_strerror(errno));
|
VLOG_ERR("failed to create inet socket: %s", sock_strerror(error));
|
||||||
|
sock = -error;
|
||||||
}
|
}
|
||||||
ovsthread_once_done(&once);
|
ovsthread_once_done(&once);
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#ifndef SOCKET_UTIL_H
|
#ifndef SOCKET_UTIL_H
|
||||||
#define SOCKET_UTIL_H 1
|
#define SOCKET_UTIL_H 1
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@@ -99,4 +100,15 @@ static inline int rpl_setsockopt(int sock, int level, int optname,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* In Windows platform, errno is not set for socket calls.
|
||||||
|
* The last error has to be gotten from WSAGetLastError(). */
|
||||||
|
static inline int sock_errno(void)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return WSAGetLastError();
|
||||||
|
#else
|
||||||
|
return errno;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* socket-util.h */
|
#endif /* socket-util.h */
|
||||||
|
@@ -1416,18 +1416,6 @@ ssl_protocol_cb(int write_p, int version OVS_UNUSED, int content_type,
|
|||||||
ds_destroy(&details);
|
ds_destroy(&details);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In Windows platform, errno is not set for socket calls.
|
|
||||||
* The last error has to be gotten from WSAGetLastError(). */
|
|
||||||
static int
|
|
||||||
sock_errno(void)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
return WSAGetLastError();
|
|
||||||
#else
|
|
||||||
return errno;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clear_handle(int fd OVS_UNUSED, HANDLE wevent OVS_UNUSED)
|
clear_handle(int fd OVS_UNUSED, HANDLE wevent OVS_UNUSED)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user