Introduce osmo_ss7_register_rx_unknown_cb() for unknown PPID/StreamID

Applications may be interested in handling data for those SCTP PPID or
IPA StreamID which libosmo-sigtran doesn't implement
natively/internally.

Let's add osmo_ss7_register_rx_unknown_cb() using which applications
can register a call-back to implement whatever behaviour they'd want for
those PPID/StreamIDs.

Change-Id: I8616f914192000df0ec6547ff4ada80e0f9042a2
This commit is contained in:
Harald Welte 2018-05-26 11:32:50 +02:00
parent 7eb45887b3
commit 5d571ce044
4 changed files with 44 additions and 13 deletions

View File

@ -408,6 +408,17 @@ int osmo_ss7_asp_send(struct osmo_ss7_asp *asp, struct msgb *msg);
int osmo_ss7_asp_restart(struct osmo_ss7_asp *asp);
int osmo_ss7_asp_use_default_lm(struct osmo_ss7_asp *asp, int log_level);
/*! Weak function to handle payload for unknown/unsupported PPID or IPA StreamID.
* This function can be overridden by application code to implement whatever handling
* it wants for such additional payloads/streams.
* \param[in] asp Application Server Process through which data was received
* \param[in] ppid_sid SCTP PPID (in sigtran case) or IPA Stream ID
* \param[in] msg Message buffer containing received data. Continues to be owned by caller!
* \return 0 on success; negative on error */
typedef int osmo_ss7_asp_rx_unknown_cb(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg);
void osmo_ss7_register_rx_unknown_cb(osmo_ss7_asp_rx_unknown_cb *cb);
#define LOGPASP(asp, subsys, level, fmt, args ...) \
LOGP(subsys, level, "asp-%s: " fmt, (asp)->cfg.name, ## args)

View File

@ -288,9 +288,7 @@ int ipa_rx_msg(struct osmo_ss7_asp *asp, struct msgb *msg)
rc = ipa_rx_msg_sccp(asp, msg);
break;
default:
LOGPASP(asp, DLSS7, LOGL_DEBUG, "Unknown Stream ID 0x%02x: %s\n",
hh->proto, msgb_hexdump(msg));
rc = -1;
rc = ss7_asp_rx_unknown(asp, hh->proto, msg);
}
return rc;

View File

@ -1450,11 +1450,8 @@ static int xua_srv_conn_cb(struct osmo_stream_srv *conn)
rc = sua_rx_msg(asp, msg);
else if (ppid == M3UA_PPID && asp->cfg.proto == OSMO_SS7_ASP_PROT_M3UA)
rc = m3ua_rx_msg(asp, msg);
else {
LOGPASP(asp, DLSS7, LOGL_NOTICE, "SCTP chunk for unknown PPID %u "
"received\n", ppid);
rc = 0;
}
else
rc = ss7_asp_rx_unknown(asp, ppid, msg);
out:
msgb_free(msg);
@ -1591,11 +1588,8 @@ static int xua_cli_read_cb(struct osmo_stream_cli *conn)
rc = sua_rx_msg(asp, msg);
else if (ppid == M3UA_PPID && asp->cfg.proto == OSMO_SS7_ASP_PROT_M3UA)
rc = m3ua_rx_msg(asp, msg);
else {
LOGPASP(asp, DLSS7, LOGL_NOTICE, "SCTP chunk for unknown PPID %u "
"received\n", ppid);
rc = 0;
}
else
rc = ss7_asp_rx_unknown(asp, ppid, msg);
out:
msgb_free(msg);
@ -1918,3 +1912,29 @@ enum osmo_ss7_as_traffic_mode osmo_ss7_tmode_from_xua(uint32_t in)
return OSMO_SS7_AS_TMOD_BCAST;
}
}
static osmo_ss7_asp_rx_unknown_cb *g_osmo_ss7_asp_rx_unknown_cb;
int ss7_asp_rx_unknown(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg)
{
if (g_osmo_ss7_asp_rx_unknown_cb)
return (*g_osmo_ss7_asp_rx_unknown_cb)(asp, ppid_mux, msg);
switch(asp->cfg.proto) {
case OSMO_SS7_ASP_PROT_IPA:
LOGPASP(asp, DLSS7, LOGL_NOTICE, "Rx IPA for unknown Stream ID 0x%02x: %s\n",
ppid_mux, msgb_hexdump(msg));
break;
default:
LOGPASP(asp, DLSS7, LOGL_NOTICE, "Rx SCTP chunk for unknown PPID %u: %s\n",
ppid_mux, msgb_hexdump(msg));
break;
}
return 0;
}
/*! Register a call-back function for unknown SCTP PPID / IPA Stream ID */
void osmo_ss7_register_rx_unknown_cb(osmo_ss7_asp_rx_unknown_cb *cb)
{
g_osmo_ss7_asp_rx_unknown_cb = cb;
}

View File

@ -78,3 +78,5 @@ int osmo_isup_party_parse(char *out_digits, const uint8_t *in,
int osmo_sccp_addr_parse(struct osmo_sccp_addr *out,
const uint8_t *addr, unsigned int addrlen);
int osmo_sccp_addr_encode(struct msgb *msg, const struct osmo_sccp_addr *in);
int ss7_asp_rx_unknown(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *msg);