aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2021-11-30 20:38:20 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2021-12-01 14:52:47 +0100
commit4cf31f187a7adfd11c3700fcf8e115c8c8490454 (patch)
tree2328509d7de8c145f0f63bfadeb2a71ca506e1a4
parentd4a1107586e8fefb18de10b9d68d63a2d3f1fe0d (diff)
stream: Factor out sctp_recvmg long code chunk
This makes it easier to follow the general path selection based on protocol type. It will also make it easier when we add new paths based on socket domain. Change-Id: Ia3e0f4407e00a2dac9ee885fe1cc1cb4b463898a
-rw-r--r--src/stream.c94
1 files changed, 51 insertions, 43 deletions
diff --git a/src/stream.c b/src/stream.c
index e4fb668..309aafe 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1290,6 +1290,56 @@ void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg)
osmo_fd_write_enable(&conn->ofd);
}
+#ifdef HAVE_LIBSCTP
+static int _sctp_recvmsg_wrapper(int fd, struct msgb *msg)
+{
+ struct sctp_sndrcvinfo sinfo;
+ int flags = 0;
+ int ret;
+
+ ret = sctp_recvmsg(fd, msgb_data(msg), msgb_tailroom(msg),
+ NULL, NULL, &sinfo, &flags);
+ if (flags & MSG_NOTIFICATION) {
+ union sctp_notification *notif = (union sctp_notification *)msgb_data(msg);
+ LOGP(DLINP, LOGL_DEBUG, "NOTIFICATION %u flags=0x%x\n", notif->sn_header.sn_type, notif->sn_header.sn_flags);
+ switch (notif->sn_header.sn_type) {
+ case SCTP_ASSOC_CHANGE:
+ LOGP(DLINP, LOGL_DEBUG, "===> ASSOC CHANGE:");
+ switch (notif->sn_assoc_change.sac_state) {
+ case SCTP_COMM_UP:
+ LOGPC(DLINP, LOGL_DEBUG, " UP\n");
+ break;
+ case SCTP_COMM_LOST:
+ LOGPC(DLINP, LOGL_DEBUG, " LOST\n");
+ break;
+ case SCTP_RESTART:
+ LOGPC(DLINP, LOGL_DEBUG, " RESTART\n");
+ break;
+ case SCTP_SHUTDOWN_COMP:
+ LOGPC(DLINP, LOGL_DEBUG, " SHUTDOWN COMP\n");
+ break;
+ case SCTP_CANT_STR_ASSOC:
+ LOGPC(DLINP, LOGL_DEBUG, " CANT STR ASSOC\n");
+ break;
+ }
+ break;
+ case SCTP_PEER_ADDR_CHANGE:
+ LOGP(DLINP, LOGL_DEBUG, "===> PEER ADDR CHANGE\n");
+ break;
+ case SCTP_SHUTDOWN_EVENT:
+ LOGP(DLINP, LOGL_DEBUG, "===> SHUTDOWN EVT\n");
+ /* Handle this like a regular disconnect */
+ return 0;
+ break;
+ }
+ return -EAGAIN;
+ }
+ msgb_sctp_ppid(msg) = ntohl(sinfo.sinfo_ppid);
+ msgb_sctp_stream(msg) = sinfo.sinfo_stream;
+ return ret;
+}
+#endif
+
/*! \brief Receive data via Osmocom stream server
* \param[in] conn Stream Server from which to receive
* \param msg pre-allocate message buffer to which received data is appended
@@ -1297,10 +1347,6 @@ void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg)
*/
int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg)
{
-#ifdef HAVE_LIBSCTP
- struct sctp_sndrcvinfo sinfo;
- int flags = 0;
-#endif
int ret;
if (!msg)
@@ -1309,45 +1355,7 @@ int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg)
switch (conn->srv->proto) {
#ifdef HAVE_LIBSCTP
case IPPROTO_SCTP:
- ret = sctp_recvmsg(conn->ofd.fd, msgb_data(msg), msgb_tailroom(msg),
- NULL, NULL, &sinfo, &flags);
- if (flags & MSG_NOTIFICATION) {
- union sctp_notification *notif = (union sctp_notification *) msgb_data(msg);
- LOGP(DLINP, LOGL_DEBUG, "NOTIFICATION %u flags=0x%x\n", notif->sn_header.sn_type, notif->sn_header.sn_flags);
- switch (notif->sn_header.sn_type) {
- case SCTP_ASSOC_CHANGE:
- LOGP(DLINP, LOGL_DEBUG, "===> ASSOC CHANGE:");
- switch (notif->sn_assoc_change.sac_state) {
- case SCTP_COMM_UP:
- LOGPC(DLINP, LOGL_DEBUG, " UP\n");
- break;
- case SCTP_COMM_LOST:
- LOGPC(DLINP, LOGL_DEBUG, " LOST\n");
- break;
- case SCTP_RESTART:
- LOGPC(DLINP, LOGL_DEBUG, " RESTART\n");
- break;
- case SCTP_SHUTDOWN_COMP:
- LOGPC(DLINP, LOGL_DEBUG, " SHUTDOWN COMP\n");
- break;
- case SCTP_CANT_STR_ASSOC:
- LOGPC(DLINP, LOGL_DEBUG, " CANT STR ASSOC\n");
- break;
- }
- break;
- case SCTP_PEER_ADDR_CHANGE:
- LOGP(DLINP, LOGL_DEBUG, "===> PEER ADDR CHANGE\n");
- break;
- case SCTP_SHUTDOWN_EVENT:
- LOGP(DLINP, LOGL_DEBUG, "===> SHUTDOWN EVT\n");
- /* Handle this like a regular disconnect */
- return 0;
- break;
- }
- return -EAGAIN;
- }
- msgb_sctp_ppid(msg) = ntohl(sinfo.sinfo_ppid);
- msgb_sctp_stream(msg) = sinfo.sinfo_stream;
+ ret = _sctp_recvmsg_wrapper(conn->ofd.fd, msg);
break;
#endif
case IPPROTO_TCP: