From 4acb333e68792a0e02606bd1c59ad4bbe6c41d4f Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Fri, 18 Sep 2020 21:46:49 -0400 Subject: [PATCH] suppress socket error message if EAGAIN [#568] --- lib/core/ogs-socket.c | 19 ++----------------- lib/gtp/path.c | 10 ++++++++-- lib/pfcp/path.c | 22 ++++++++++++++++------ src/sgwc/pfcp-path.c | 5 ++++- src/sgwu/pfcp-path.c | 5 ++++- src/smf/pfcp-path.c | 5 ++++- src/upf/pfcp-path.c | 5 ++++- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/lib/core/ogs-socket.c b/lib/core/ogs-socket.c index 359d3ec83..726eb01c9 100644 --- a/lib/core/ogs-socket.c +++ b/lib/core/ogs-socket.c @@ -220,23 +220,14 @@ ssize_t ogs_read(ogs_socket_t fd, void *buf, size_t len) ssize_t ogs_send(ogs_socket_t fd, const void *buf, size_t len, int flags) { - ssize_t size; - ogs_assert(fd != INVALID_SOCKET); - size = send(fd, buf, len, flags); - if (size < 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, - "send(len:%d) failed", (int)len); - } - - return size; + return send(fd, buf, len, flags); } ssize_t ogs_sendto(ogs_socket_t fd, const void *buf, size_t len, int flags, const ogs_sockaddr_t *to) { - ssize_t size; socklen_t addrlen; ogs_assert(fd != INVALID_SOCKET); @@ -245,13 +236,7 @@ ssize_t ogs_sendto(ogs_socket_t fd, addrlen = ogs_sockaddr_len(to); ogs_assert(addrlen); - size = sendto(fd, buf, len, flags, &to->sa, addrlen); - if (size < 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, - "sendto(len:%d) failed", (int)len); - } - - return size; + return sendto(fd, buf, len, flags, &to->sa, addrlen); } ssize_t ogs_recv(ogs_socket_t fd, void *buf, size_t len, int flags) diff --git a/lib/gtp/path.c b/lib/gtp/path.c index 95276aa67..e4f3bbab9 100644 --- a/lib/gtp/path.c +++ b/lib/gtp/path.c @@ -88,7 +88,10 @@ int ogs_gtp_send(ogs_gtp_node_t *gnode, ogs_pkbuf_t *pkbuf) sent = ogs_send(sock->fd, pkbuf->data, pkbuf->len, 0); if (sent < 0 || sent != pkbuf->len) { - ogs_error("ogs_send() failed"); + if (ogs_socket_errno != OGS_EAGAIN) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_gtp_send() failed"); + } return OGS_ERROR; } @@ -110,7 +113,10 @@ int ogs_gtp_sendto(ogs_gtp_node_t *gnode, ogs_pkbuf_t *pkbuf) sent = ogs_sendto(sock->fd, pkbuf->data, pkbuf->len, 0, addr); if (sent < 0 || sent != pkbuf->len) { - ogs_error("ogs_send() failed"); + if (ogs_socket_errno != OGS_EAGAIN) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_gtp_sendto() failed"); + } return OGS_ERROR; } diff --git a/lib/pfcp/path.c b/lib/pfcp/path.c index 76aab762c..17b64393a 100644 --- a/lib/pfcp/path.c +++ b/lib/pfcp/path.c @@ -89,7 +89,8 @@ int ogs_pfcp_send(ogs_pfcp_node_t *node, ogs_pkbuf_t *pkbuf) sent = ogs_send(sock->fd, pkbuf->data, pkbuf->len, 0); if (sent < 0 || sent != pkbuf->len) { - ogs_error("ogs_send() failed"); + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_pfcp_send() failed"); return OGS_ERROR; } @@ -111,7 +112,8 @@ int ogs_pfcp_sendto(ogs_pfcp_node_t *node, ogs_pkbuf_t *pkbuf) sent = ogs_sendto(sock->fd, pkbuf->data, pkbuf->len, 0, addr); if (sent < 0 || sent != pkbuf->len) { - ogs_error("ogs_sendto() failed"); + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_pfcp_sendto() failed"); return OGS_ERROR; } @@ -327,8 +329,12 @@ void ogs_pfcp_send_g_pdu(ogs_pfcp_pdr_t *pdr, ogs_pkbuf_t *sendbuf) ogs_debug("SEND G-PDU to Peer[%s] : TEID[0x%x]", OGS_ADDR(&gnode->addr, buf), far->outer_header_creation.teid); rv = ogs_gtp_sendto(gnode, sendbuf); - if (rv != OGS_OK) - ogs_error("ogs_gtp_sendto() failed"); + if (rv != OGS_OK) { + if (ogs_socket_errno != OGS_EAGAIN) { + ogs_error("SEND G-PDU to Peer[%s] : TEID[0x%x]", + OGS_ADDR(&gnode->addr, buf), far->outer_header_creation.teid); + } + } ogs_pkbuf_free(sendbuf); } @@ -407,8 +413,12 @@ void ogs_pfcp_send_end_marker(ogs_pfcp_pdr_t *pdr) ogs_debug("SEND End Marker to Peer[%s] : TEID[0x%x]", OGS_ADDR(&gnode->addr, buf), far->outer_header_creation.teid); rv = ogs_gtp_sendto(gnode, sendbuf); - if (rv != OGS_OK) - ogs_error("ogs_gtp_sendto() failed"); + if (rv != OGS_OK) { + if (ogs_socket_errno != OGS_EAGAIN) { + ogs_error("SEND End Marker to Peer[%s] : TEID[0x%x]", + OGS_ADDR(&gnode->addr, buf), far->outer_header_creation.teid); + } + } ogs_pkbuf_free(sendbuf); } diff --git a/src/sgwc/pfcp-path.c b/src/sgwc/pfcp-path.c index 8c6aa1189..bd3df5b7b 100644 --- a/src/sgwc/pfcp-path.c +++ b/src/sgwc/pfcp-path.c @@ -95,7 +95,10 @@ static void pfcp_recv_cb(short when, ogs_socket_t fd, void *data) rsp.type = OGS_PFCP_VERSION_NOT_SUPPORTED_RESPONSE_TYPE; rsp.length = htobe16(4); rsp.sqn_only = h->sqn_only; - ogs_sendto(fd, &rsp, 8, 0, &from); + if (ogs_sendto(fd, &rsp, 8, 0, &from) < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_sendto() failed"); + } ogs_pkbuf_free(pkbuf); return; diff --git a/src/sgwu/pfcp-path.c b/src/sgwu/pfcp-path.c index 2aa951d35..c16b16ab5 100644 --- a/src/sgwu/pfcp-path.c +++ b/src/sgwu/pfcp-path.c @@ -92,7 +92,10 @@ static void pfcp_recv_cb(short when, ogs_socket_t fd, void *data) rsp.type = OGS_PFCP_VERSION_NOT_SUPPORTED_RESPONSE_TYPE; rsp.length = htobe16(4); rsp.sqn_only = h->sqn_only; - ogs_sendto(fd, &rsp, 8, 0, &from); + if (ogs_sendto(fd, &rsp, 8, 0, &from) < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_sendto() failed"); + } ogs_pkbuf_free(pkbuf); return; diff --git a/src/smf/pfcp-path.c b/src/smf/pfcp-path.c index 3ca8c66ee..929de44a1 100644 --- a/src/smf/pfcp-path.c +++ b/src/smf/pfcp-path.c @@ -94,7 +94,10 @@ static void pfcp_recv_cb(short when, ogs_socket_t fd, void *data) rsp.type = OGS_PFCP_VERSION_NOT_SUPPORTED_RESPONSE_TYPE; rsp.length = htobe16(4); rsp.sqn_only = h->sqn_only; - ogs_sendto(fd, &rsp, 8, 0, &from); + if (ogs_sendto(fd, &rsp, 8, 0, &from) < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_sendto() failed"); + } ogs_pkbuf_free(pkbuf); return; diff --git a/src/upf/pfcp-path.c b/src/upf/pfcp-path.c index 66bdc24fa..a7f8cf027 100644 --- a/src/upf/pfcp-path.c +++ b/src/upf/pfcp-path.c @@ -95,7 +95,10 @@ static void pfcp_recv_cb(short when, ogs_socket_t fd, void *data) rsp.type = OGS_PFCP_VERSION_NOT_SUPPORTED_RESPONSE_TYPE; rsp.length = htobe16(4); rsp.sqn_only = h->sqn_only; - ogs_sendto(fd, &rsp, 8, 0, &from); + if (ogs_sendto(fd, &rsp, 8, 0, &from) < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_sendto() failed"); + } ogs_pkbuf_free(pkbuf); return;