Change in libosmo-netif[master]: stream: Factor out sctp_recvmg long code chunk

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Tue Nov 30 19:55:04 UTC 2021


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/26429 )


Change subject: stream: Factor out sctp_recvmg long code chunk
......................................................................

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
---
M src/stream.c
1 file changed, 51 insertions(+), 43 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/29/26429/1

diff --git a/src/stream.c b/src/stream.c
index e4fb668..a36ea9e 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1290,6 +1290,56 @@
 	osmo_fd_write_enable(&conn->ofd);
 }
 
+#ifdef HAVE_LIBSCTP
+static int _sctp_recvmg_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 @@
  */
 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 @@
 	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_recvmg_wrapper(conn->ofd.fd, msg);
 		break;
 #endif
 	case IPPROTO_TCP:

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/26429
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e0f4407e00a2dac9ee885fe1cc1cb4b463898a
Gerrit-Change-Number: 26429
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211130/7b733946/attachment.htm>


More information about the gerrit-log mailing list