diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c index 90c72a9b..6221d7bc 100644 --- a/src/osmo_ss7_asp.c +++ b/src/osmo_ss7_asp.c @@ -602,9 +602,9 @@ void osmo_ss7_asp_destroy(struct osmo_ss7_asp *asp) talloc_free(asp); } -static int xua_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg); -static int ipa_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg); -static int m3ua_tcp_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg); +static int xua_cli_read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg); +static int ipa_cli_read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg); +static int m3ua_tcp_cli_read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg); static int xua_cli_connect_cb(struct osmo_stream_cli *cli); static int xua_cli_close_and_reconnect(struct osmo_stream_cli *cli); @@ -953,11 +953,21 @@ static int xua_cli_close_and_reconnect(struct osmo_stream_cli *cli) } /* read call-back for IPA/SCCPlite socket */ -static int ipa_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg) +static int ipa_cli_read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg) { int fd = osmo_stream_cli_get_fd(conn); struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(conn); + if (res <= 0) { + if (res == -EAGAIN) { + msgb_free(msg); + return 0; + } + xua_cli_close_and_reconnect(conn); + msgb_free(msg); + return res; + } + msg->dst = asp; rate_ctr_inc2(asp->ctrg, SS7_ASP_CTR_PKT_RX_TOTAL); /* we can use the 'fd' return value of osmo_stream_srv_get_fd() here unverified as all we do @@ -966,7 +976,7 @@ static int ipa_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg) } /* read call-back for M3UA-over-TCP socket */ -static int m3ua_tcp_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg) +static int m3ua_tcp_cli_read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg) { const struct xua_common_hdr *hdr; @@ -980,10 +990,10 @@ static int m3ua_tcp_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg) else msgb_sctp_stream(msg) = 0; - return xua_cli_read_cb(conn, msg); + return xua_cli_read_cb(conn, res, msg); } -static int xua_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg) +static int xua_cli_read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg) { struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(conn); unsigned int ppid; @@ -1008,6 +1018,17 @@ static int xua_cli_read_cb(struct osmo_stream_cli *conn, struct msgb *msg) default: break; } + if (rc == 0) + xua_cli_close_and_reconnect(conn); + rc = 0; + goto out; + } + if (rc < 0) { + xua_cli_close_and_reconnect(conn); + goto out; + } else if (rc == 0) { + xua_cli_close_and_reconnect(conn); + goto out; }