pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/34083 )
Change subject: stream_srv: sctp: Log error cause of COMM_LOST event
......................................................................
stream_srv: sctp: Log error cause of COMM_LOST event
RFC 6458 6.1.1:
"""
sac_error: If the state was reached due to an error condition (e.g.,
SCTP_COMM_LOST), any relevant error information is available in
this field. This corresponds to the protocol error codes defined
in [RFC4960].
"""
Change-Id: Ie48360d22ce1e35eefb1a305dde106948dfa80e8
---
M src/stream_srv.c
1 file changed, 18 insertions(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
diff --git a/src/stream_srv.c b/src/stream_srv.c
index cccb811..6c50a69 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -856,7 +856,8 @@
LOGPC(DLINP, LOGL_DEBUG, " UP\n");
break;
case SCTP_COMM_LOST:
- LOGPC(DLINP, LOGL_DEBUG, " LOST\n");
+ LOGPC(DLINP, LOGL_DEBUG, " COMM_LOST (err: %s)\n",
+ osmo_sctp_sn_error_str(notif->sn_assoc_change.sac_error));
/* Handle this like a regular disconnect */
return 0;
case SCTP_RESTART:
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/34083
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Ie48360d22ce1e35eefb1a305dde106948dfa80e8
Gerrit-Change-Number: 34083
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/34072 )
Change subject: stream_srv: call setsockopt(SO_NOSIGPIPE) also in srv sockets
......................................................................
stream_srv: call setsockopt(SO_NOSIGPIPE) also in srv sockets
Commit 5b0ad8bd851e4ce888b386be68c1821e4f2ca301 added call to
setsockopt(SO_NOSIGPIPE) in order to avoid SIGPIPE being signalled on
platforms not supporting send() flag MSG_NOSIGNAL (macOS, FreeBSD
etc...).
While it may be a topic to discuss whether we support those platorms or
not, the fact that we call an extra setsockopt() during socket creation
doesn't hurt much, and for sure we want to have the same behavior in
client and server.
Hence, this commit adds the same behavior pesent in srv sockets to cli
ones.
Change-Id: I867d8e244e473679abb7e7e7a9b531eeed046436
---
M src/stream_cli.c
M src/stream_srv.c
2 files changed, 38 insertions(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
diff --git a/src/stream_cli.c b/src/stream_cli.c
index 72a86c3..9845f14 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -308,7 +308,7 @@
int val = 1;
ret = setsockopt(osmo_stream_cli_fd(cli), SOL_SOCKET, SO_NOSIGPIPE, (void *)&val, sizeof(val));
if (ret < 0)
- LOGSCLI(cli, LOGL_DEBUG, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno));
+ LOGSCLI(cli, LOGL_ERROR, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno));
return ret;
#else
return 0;
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 1ef2cc4..6898ef4 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -97,6 +97,20 @@
int flags;
};
+static int _setsockopt_nosigpipe(struct osmo_stream_srv_link *link, int new_fd)
+{
+#ifdef SO_NOSIGPIPE
+ int ret;
+ int val = 1;
+ ret = setsockopt(new_fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&val, sizeof(val));
+ if (ret < 0)
+ LOGSLNK(link, LOGL_ERROR, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno));
+ return ret;
+#else
+ return 0;
+#endif
+}
+
static int osmo_stream_srv_link_ofd_cb(struct osmo_fd *ofd, unsigned int what)
{
int ret;
@@ -117,6 +131,7 @@
case AF_UNIX:
LOGSLNK(link, LOGL_DEBUG, "accept()ed new link on fd %d\n",
sock_fd);
+ _setsockopt_nosigpipe(link, sock_fd);
break;
case AF_INET6:
case AF_INET:
@@ -124,6 +139,7 @@
osmo_sockaddr_to_str(&osa));
if (link->proto == IPPROTO_SCTP) {
+ _setsockopt_nosigpipe(link, sock_fd);
ret = stream_sctp_sock_activate_events(sock_fd);
if (ret < 0)
goto error_close_socket;
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/34072
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I867d8e244e473679abb7e7e7a9b531eeed046436
Gerrit-Change-Number: 34072
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/34074 )
Change subject: stream: Append data to current tail of message upon recv()
......................................................................
stream: Append data to current tail of message upon recv()
The previous behavior was not standarized, and even erratic under some
code paths (passing msgb_data() and size=msgb_tailroom()).
This patch standarizes the behavior, and makes it possible to append
content if the user wishes so instead of erasing old data in the msgb
passed to it.
Change-Id: I2cfcd4f61545e6a76d84495c3467999efccf22df
---
M src/stream_cli.c
M src/stream_srv.c
2 files changed, 21 insertions(+), 5 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
Jenkins Builder: Verified
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
diff --git a/src/stream_cli.c b/src/stream_cli.c
index 9845f14..0e075b8 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -917,7 +917,7 @@
OSMO_ASSERT(cli);
OSMO_ASSERT(msg);
- ret = recv(cli->ofd.fd, msg->data, msg->data_len, 0);
+ ret = recv(cli->ofd.fd, msg->tail, msgb_tailroom(msg), 0);
if (ret < 0) {
if (errno == EPIPE || errno == ECONNRESET)
LOGSCLI(cli, LOGL_ERROR, "lost connection with srv\n");
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 4d8d4d3..be43a80 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -826,14 +826,15 @@
struct sctp_sndrcvinfo sinfo;
int flags = 0;
int ret;
+ uint8_t *data = msg->tail;
- ret = sctp_recvmsg(fd, msgb_data(msg), msgb_tailroom(msg),
+ ret = sctp_recvmsg(fd, data, msgb_tailroom(msg),
NULL, NULL, &sinfo, &flags);
msgb_sctp_msg_flags(msg) = 0;
msgb_sctp_ppid(msg) = ntohl(sinfo.sinfo_ppid);
msgb_sctp_stream(msg) = sinfo.sinfo_stream;
if (flags & MSG_NOTIFICATION) {
- union sctp_notification *notif = (union sctp_notification *)msgb_data(msg);
+ union sctp_notification *notif = (union sctp_notification *)data;
LOGP(DLINP, LOGL_DEBUG, "NOTIFICATION %u flags=0x%x\n", notif->sn_header.sn_type, notif->sn_header.sn_flags);
msgb_put(msg, sizeof(union sctp_notification));
msgb_sctp_msg_flags(msg) = OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION;
@@ -908,7 +909,7 @@
switch (conn->srv->sk_domain) {
case AF_UNIX:
- ret = recv(conn->ofd.fd, msgb_data(msg), msgb_tailroom(msg), 0);
+ ret = recv(conn->ofd.fd, msg->tail, msgb_tailroom(msg), 0);
break;
case AF_INET:
case AF_INET6:
@@ -921,7 +922,7 @@
#endif
case IPPROTO_TCP:
default:
- ret = recv(conn->ofd.fd, msgb_data(msg), msgb_tailroom(msg), 0);
+ ret = recv(conn->ofd.fd, msg->tail, msgb_tailroom(msg), 0);
break;
}
break;
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/34074
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I2cfcd4f61545e6a76d84495c3467999efccf22df
Gerrit-Change-Number: 34074
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/34078 )
Change subject: stream_srv: Handle ESHUTDOWN and other write() errors destroying the socket
......................................................................
stream_srv: Handle ESHUTDOWN and other write() errors destroying the socket
If internal send() fails with a fatal error, it should destroy the
socket. The user will know about the event through the close_cb() called
during osmo_stream_srv_destroy().
As a result, the socket is not closed when receiving SHUTDOWN by the
peer (through SCTP MSG_NOTIFICATION), but keep it alive since the socket
can still keep receiving data from the peer. Only fail if write() to
that read-only socket is attempted.
Related: OS#6134
Change-Id: I84ddebabdffe47733cb529bcfebec8757e6a172b
---
M src/stream_srv.c
1 file changed, 34 insertions(+), 4 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
osmith: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
diff --git a/src/stream_srv.c b/src/stream_srv.c
index be43a80..cccb811 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -588,8 +588,18 @@
return;
}
- if (ret == -1) /* send(): On error -1 is returned, and errno is set appropriately */
- LOGSSRV(conn, LOGL_ERROR, "error to send: %s\n", strerror(errno));
+ if (ret == -1) {/* send(): On error -1 is returned, and errno is set appropriately */
+ int err = errno;
+ LOGSSRV(conn, LOGL_ERROR, "send(len=%u) error: %s\n", msgb_length(msg), strerror(err));
+ if (err == EAGAIN) {
+ /* Re-add at the start of the queue to re-attempt: */
+ llist_add(&msg->list, &conn->tx_queue);
+ return;
+ }
+ msgb_free(msg);
+ osmo_stream_srv_destroy(conn);
+ return;
+ }
msgb_free(msg);
@@ -877,8 +887,9 @@
break;
case SCTP_SHUTDOWN_EVENT:
LOGP(DLINP, LOGL_DEBUG, "===> SHUTDOWN EVT\n");
- /* Handle this like a regular disconnect */
- return 0;
+ /* RFC6458 3.1.4: Any attempt to send more data will cause sendmsg()
+ * to return with an ESHUTDOWN error. */
+ break;
}
return -EAGAIN;
}
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/34078
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I84ddebabdffe47733cb529bcfebec8757e6a172b
Gerrit-Change-Number: 34078
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged