pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-sccp/+/34089 )
Change subject: ss7: Use libosmo-netif's osmo_stream_{cli,srv}_recv() APIs
......................................................................
ss7: Use libosmo-netif's osmo_stream_{cli,srv}_recv() APIs
Since libosmo-netif.git Change-Id
I4cb94d264109f1b763cccd44c6ba049cc7509319, we receive SCTP notifications
in both client and srv, so there's no real need to use sctp_recvmsg()
directly.
Change-Id: If3d78b636e8e224aa9c8597d0b242e29d3e3c84e
---
M TODO-RELEASE
M src/osmo_ss7.c
2 files changed, 58 insertions(+), 59 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/89/34089/1
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 000f9f3..753e24a 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -10,4 +10,5 @@
libosmocore >1.8.0 uses new osmo_prim_operation_name()
libosmo-netif > 1.3.0 uses osmo_stream_*_set_name()
libosmo-sccp add API osmo_ss7_asp_get_name(), osmo_ss7_asp_get_proto()
-osmo_sccp_simple_client_on_ss7_id() behavior change: ASPs asp-clnt-* defined through VTY
must explicitly configure "role" and "sctp-role"
\ No newline at end of file
+osmo_sccp_simple_client_on_ss7_id() behavior change: ASPs asp-clnt-* defined through VTY
must explicitly configure "role" and "sctp-role"
+libosmo-netif > 1.3.0 flag OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION set by
osmo_stream_cli_recv()
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 22139b9..5befdee 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -1781,22 +1781,43 @@
/* netif code tells us we can read something from the socket */
static int xua_srv_conn_cb(struct osmo_stream_srv *conn)
{
- struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn);
struct osmo_ss7_asp *asp = osmo_stream_srv_get_data(conn);
struct msgb *msg = m3ua_msgb_alloc("xUA Server Rx");
- struct sctp_sndrcvinfo sinfo;
unsigned int ppid;
- int flags = 0;
+ int flags;
int rc;
if (!msg)
return -ENOMEM;
/* read xUA message from socket and process it */
- rc = sctp_recvmsg(ofd->fd, msgb_data(msg), msgb_tailroom(msg),
- NULL, NULL, &sinfo, &flags);
+ rc = osmo_stream_srv_recv(conn, msg);
+ flags = msgb_sctp_msg_flags(msg);
+
LOGPASP(asp, DLSS7, LOGL_DEBUG, "%s(): sctp_recvmsg() returned %d
(flags=0x%x)\n",
__func__, rc, flags);
+
+ if (flags & OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION) {
+ union sctp_notification *notif = (union sctp_notification *) msgb_data(msg);
+ log_sctp_notification(asp, "xUA CLNT", notif);
+
+ switch (notif->sn_header.sn_type) {
+ case SCTP_ASSOC_CHANGE:
+ if (notif->sn_assoc_change.sac_state == SCTP_RESTART)
+ xua_asp_send_xlm_prim_simple(asp, OSMO_XLM_PRIM_M_SCTP_RESTART,
+ PRIM_OP_INDICATION);
+ default:
+ break;
+ }
+
+ if (rc == 0) {
+ osmo_stream_srv_destroy(conn);
+ rc = -EBADF;
+ } else {
+ rc = 0;
+ }
+ goto out;
+ }
if (rc < 0) {
osmo_stream_srv_destroy(conn);
rc = -EBADF;
@@ -1805,38 +1826,10 @@
osmo_stream_srv_destroy(conn);
rc = -EBADF;
goto out;
- } else {
- msgb_put(msg, rc);
}
- if (flags & MSG_NOTIFICATION) {
- union sctp_notification *notif = (union sctp_notification *) msgb_data(msg);
-
- log_sctp_notification(asp, "xUA SRV", notif);
-
- switch (notif->sn_header.sn_type) {
- case SCTP_SHUTDOWN_EVENT:
- osmo_stream_srv_destroy(conn);
- rc = -EBADF;
- break;
- case SCTP_ASSOC_CHANGE:
- if (notif->sn_assoc_change.sac_state == SCTP_RESTART)
- xua_asp_send_xlm_prim_simple(asp, OSMO_XLM_PRIM_M_SCTP_RESTART,
- PRIM_OP_INDICATION);
- rc = 0;
- break;
- default:
- rc = 0;
- break;
- }
- goto out;
- }
-
- ppid = ntohl(sinfo.sinfo_ppid);
- msgb_sctp_ppid(msg) = ppid;
- msgb_sctp_stream(msg) = sinfo.sinfo_stream;
+ ppid = msgb_sctp_ppid(msg);
msg->dst = asp;
-
rate_ctr_inc2(asp->ctrg, SS7_ASP_CTR_PKT_RX_TOTAL);
if (ppid == SUA_PPID && asp->cfg.proto == OSMO_SS7_ASP_PROT_SUA)
@@ -1924,40 +1917,27 @@
static int xua_cli_read_cb(struct osmo_stream_cli *conn)
{
- struct osmo_fd *ofd = osmo_stream_cli_get_ofd(conn);
struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(conn);
struct msgb *msg = m3ua_msgb_alloc("xUA Client Rx");
- struct sctp_sndrcvinfo sinfo;
unsigned int ppid;
- int flags = 0;
+ int flags;
int rc;
if (!msg)
return -ENOMEM;
/* read xUA message from socket and process it */
- rc = sctp_recvmsg(ofd->fd, msgb_data(msg), msgb_tailroom(msg),
- NULL, NULL, &sinfo, &flags);
+ rc = osmo_stream_cli_recv(conn, msg);
+ flags = msgb_sctp_msg_flags(msg);
+
LOGPASP(asp, DLSS7, LOGL_DEBUG, "%s(): sctp_recvmsg() returned %d
(flags=0x%x)\n",
__func__, rc, flags);
- if (rc < 0) {
- xua_cli_close_and_reconnect(conn);
- goto out;
- } else if (rc == 0) {
- xua_cli_close_and_reconnect(conn);
- } else {
- msgb_put(msg, rc);
- }
- if (flags & MSG_NOTIFICATION) {
+ if (flags & OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION) {
union sctp_notification *notif = (union sctp_notification *) msgb_data(msg);
-
log_sctp_notification(asp, "xUA CLNT", notif);
switch (notif->sn_header.sn_type) {
- case SCTP_SHUTDOWN_EVENT:
- xua_cli_close_and_reconnect(conn);
- break;
case SCTP_ASSOC_CHANGE:
if (notif->sn_assoc_change.sac_state == SCTP_RESTART)
xua_asp_send_xlm_prim_simple(asp, OSMO_XLM_PRIM_M_SCTP_RESTART,
@@ -1965,18 +1945,22 @@
default:
break;
}
+
+ if (rc == 0)
+ xua_cli_close_and_reconnect(conn);
rc = 0;
goto out;
}
-
- if (rc == 0)
+ if (rc < 0) {
+ xua_cli_close_and_reconnect(conn);
goto out;
+ } else if (rc == 0) {
+ xua_cli_close_and_reconnect(conn);
+ goto out;
+ }
- ppid = ntohl(sinfo.sinfo_ppid);
- msgb_sctp_ppid(msg) = ppid;
- msgb_sctp_stream(msg) = sinfo.sinfo_stream;
+ ppid = msgb_sctp_ppid(msg);
msg->dst = asp;
-
rate_ctr_inc2(asp->ctrg, SS7_ASP_CTR_PKT_RX_TOTAL);
if (ppid == SUA_PPID && asp->cfg.proto == OSMO_SS7_ASP_PROT_SUA)
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-sccp/+/34089
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: If3d78b636e8e224aa9c8597d0b242e29d3e3c84e
Gerrit-Change-Number: 34089
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange