aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-11-20 12:31:38 +0100
committerHarald Welte <laforge@osmocom.org>2023-11-25 17:28:59 +0100
commit04ca01eaeb28a32670aa23898bab5c2d186851af (patch)
tree51f5201ae4c94b2bdac7061ec722ed26336740be
parent42ed1bf15d4659a3691f428c10faffcc975d8a5f (diff)
port from osmo_stream_*_get_ofd() to osmo_stream_srv_get_fd()
The existing/old osmo_stream_{srv,cli}_get_ofd() API functions are only compatible with OSMO_FD mode of libosmo-netif/stream. In the OSMO_IO mode, there is no osmo_fd involved, and hence those functions are illegal to call. Let's instead migrate over to the new osmo_stream_{srv,cli}_get_fd() which directly return the file descriptor integer value. Change-Id: I12c66badfb4bdfdfe71f1716de960d353d3548b1 Related: OS#5752
-rw-r--r--TODO-RELEASE3
-rw-r--r--src/osmo_ss7_asp.c75
-rw-r--r--src/osmo_ss7_vty.c4
-rw-r--r--src/xua_asp_fsm.c8
4 files changed, 56 insertions, 34 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index ae21a12..1e4c41a 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,4 +7,5 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
-libosmocore >1.9.0 osmo_sock_multiaddr_{add,del}_local_addr() \ No newline at end of file
+libosmocore >1.9.0 osmo_sock_multiaddr_{add,del}_local_addr()
+libosmo-netif >1.4.0 osmo_stream_{srv,cli}_get_fd()
diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c
index 0662085..55e5a29 100644
--- a/src/osmo_ss7_asp.c
+++ b/src/osmo_ss7_asp.c
@@ -171,7 +171,7 @@ static unsigned int g_ss7_asp_rcg_idx;
int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned int loc_idx)
{
const char *new_loc_addr;
- struct osmo_fd *ofd;
+ int fd;
OSMO_ASSERT(loc_idx < asp->cfg.local.host_cnt);
new_loc_addr = asp->cfg.local.host[loc_idx];
@@ -180,17 +180,20 @@ int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned int
new_loc_addr);
if (asp->cfg.is_server)
- ofd = osmo_stream_srv_get_ofd(asp->server);
+ fd = osmo_stream_srv_get_fd(asp->server);
else
- ofd = osmo_stream_cli_get_ofd(asp->client);
+ fd = osmo_stream_cli_get_fd(asp->client);
- return osmo_sock_multiaddr_add_local_addr(ofd->fd, &new_loc_addr, 1);
+ if (fd < 0)
+ return fd;
+
+ return osmo_sock_multiaddr_add_local_addr(fd, &new_loc_addr, 1);
}
int ss7_asp_apply_drop_local_address(const struct osmo_ss7_asp *asp, unsigned int loc_idx)
{
const char *new_loc_addr;
- struct osmo_fd *ofd;
+ int fd;
OSMO_ASSERT(loc_idx < asp->cfg.local.host_cnt);
new_loc_addr = asp->cfg.local.host[loc_idx];
@@ -199,20 +202,22 @@ int ss7_asp_apply_drop_local_address(const struct osmo_ss7_asp *asp, unsigned in
new_loc_addr);
if (asp->cfg.is_server)
- ofd = osmo_stream_srv_get_ofd(asp->server);
+ fd = osmo_stream_srv_get_fd(asp->server);
else
- ofd = osmo_stream_cli_get_ofd(asp->client);
+ fd = osmo_stream_cli_get_fd(asp->client);
+
+ if (fd < 0)
+ return fd;
- return osmo_sock_multiaddr_del_local_addr(ofd->fd, &new_loc_addr, 1);
+ return osmo_sock_multiaddr_del_local_addr(fd, &new_loc_addr, 1);
}
int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp)
{
- struct osmo_fd *ofd;
struct osmo_sockaddr_str addr_str;
struct osmo_sockaddr addr;
uint16_t local_port;
- int rc;
+ int fd, rc;
/* No SCTP Peer Primary Address explicitly configured, do nothing. */
if (asp->cfg.local.idx_primary == -1)
@@ -220,13 +225,16 @@ int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp)
OSMO_ASSERT(asp->cfg.local.idx_primary < asp->cfg.local.host_cnt);
if (asp->cfg.is_server)
- ofd = osmo_stream_srv_get_ofd(asp->server);
+ fd = osmo_stream_srv_get_fd(asp->server);
else
- ofd = osmo_stream_cli_get_ofd(asp->client);
+ fd = osmo_stream_cli_get_fd(asp->client);
+
+ if (fd < 0)
+ return fd;
if (asp->cfg.local.port == 0) {
char port_buf[16];
- osmo_sock_get_local_ip_port(ofd->fd, port_buf, sizeof(port_buf));
+ osmo_sock_get_local_ip_port(fd, port_buf, sizeof(port_buf));
local_port = atoi(port_buf);
} else {
local_port = asp->cfg.local.port;
@@ -241,17 +249,16 @@ int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp)
return rc;
LOGPASP(asp, DLSS7, LOGL_INFO, "Set Peer's Primary Address %s\n",
osmo_sockaddr_to_str(&addr));
- rc = _setsockopt_peer_primary_addr(ofd->fd, &addr);
+ rc = _setsockopt_peer_primary_addr(fd, &addr);
return rc;
}
int ss7_asp_apply_primary_address(const struct osmo_ss7_asp *asp)
{
- struct osmo_fd *ofd;
struct osmo_sockaddr_str addr_str;
struct osmo_sockaddr addr;
- int rc;
+ int fd, rc;
/* No SCTP Primary Address explicitly configured, do nothing. */
if (asp->cfg.remote.idx_primary == -1)
@@ -259,9 +266,12 @@ int ss7_asp_apply_primary_address(const struct osmo_ss7_asp *asp)
OSMO_ASSERT(asp->cfg.remote.idx_primary < asp->cfg.remote.host_cnt);
if (asp->cfg.is_server)
- ofd = osmo_stream_srv_get_ofd(asp->server);
+ fd = osmo_stream_srv_get_fd(asp->server);
else
- ofd = osmo_stream_cli_get_ofd(asp->client);
+ fd = osmo_stream_cli_get_fd(asp->client);
+
+ if (fd < 0)
+ return fd;
rc = osmo_sockaddr_str_from_str(&addr_str,
asp->cfg.remote.host[asp->cfg.remote.idx_primary],
@@ -273,7 +283,7 @@ int ss7_asp_apply_primary_address(const struct osmo_ss7_asp *asp)
return rc;
LOGPASP(asp, DLSS7, LOGL_INFO, "Set Primary Address %s\n",
osmo_sockaddr_to_str(&addr));
- rc = _setsockopt_primary_addr(ofd->fd, &addr);
+ rc = _setsockopt_primary_addr(fd, &addr);
return rc;
}
@@ -729,13 +739,15 @@ static void log_sctp_notification(struct osmo_ss7_asp *asp, const char *pfx,
/* netif code tells us we can read something from the socket */
int ss7_asp_ipa_srv_conn_cb(struct osmo_stream_srv *conn)
{
- struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn);
+ int fd = osmo_stream_srv_get_fd(conn);
struct osmo_ss7_asp *asp = osmo_stream_srv_get_data(conn);
struct msgb *msg = NULL;
int rc;
+ OSMO_ASSERT(fd >= 0);
+
/* read IPA message from socket and process it */
- rc = ipa_msg_recv_buffered(ofd->fd, &msg, &asp->pending_msg);
+ rc = ipa_msg_recv_buffered(fd, &msg, &asp->pending_msg);
LOGPASP(asp, DLSS7, LOGL_DEBUG, "%s(): ipa_msg_recv_buffered() returned %d\n",
__func__, rc);
if (rc <= 0) {
@@ -754,7 +766,9 @@ int ss7_asp_ipa_srv_conn_cb(struct osmo_stream_srv *conn)
}
msg->dst = asp;
rate_ctr_inc2(asp->ctrg, SS7_ASP_CTR_PKT_RX_TOTAL);
- return ipa_rx_msg(asp, msg, ofd->fd & 0xf);
+ /* we can use the 'fd' return value of osmo_stream_srv_get_fd() here unverified as all we do
+ * is 'roll the dice' to obtain a 4-bit SLS value. */
+ return ipa_rx_msg(asp, msg, fd & 0xf);
}
/* netif code tells us we can read something from the socket */
@@ -827,13 +841,16 @@ out:
/* client has established SCTP connection to server */
static int xua_cli_connect_cb(struct osmo_stream_cli *cli)
{
- struct osmo_fd *ofd = osmo_stream_cli_get_ofd(cli);
+ int fd = osmo_stream_cli_get_fd(cli);
struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(cli);
int rc = 0;
+ if (fd < 0)
+ return fd;
+
/* update the socket name */
talloc_free(asp->sock_name);
- asp->sock_name = osmo_sock_get_name(asp, ofd->fd);
+ asp->sock_name = osmo_sock_get_name(asp, fd);
LOGPASP(asp, DLSS7, LOGL_INFO, "Client connected %s\n", asp->sock_name);
@@ -877,13 +894,15 @@ static void 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 osmo_fd *ofd = osmo_stream_cli_get_ofd(conn);
+ int fd = osmo_stream_cli_get_fd(conn);
struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(conn);
struct msgb *msg = NULL;
int rc;
+ OSMO_ASSERT(fd >= 0);
+
/* read IPA message from socket and process it */
- rc = ipa_msg_recv_buffered(ofd->fd, &msg, &asp->pending_msg);
+ rc = ipa_msg_recv_buffered(fd, &msg, &asp->pending_msg);
LOGPASP(asp, DLSS7, LOGL_DEBUG, "%s(): ipa_msg_recv_buffered() returned %d\n",
__func__, rc);
if (rc <= 0) {
@@ -902,7 +921,9 @@ static int ipa_cli_read_cb(struct osmo_stream_cli *conn)
}
msg->dst = asp;
rate_ctr_inc2(asp->ctrg, SS7_ASP_CTR_PKT_RX_TOTAL);
- return ipa_rx_msg(asp, msg, ofd->fd & 0xf);
+ /* we can use the 'fd' return value of osmo_stream_srv_get_fd() here unverified as all we do
+ * is 'roll the dice' to obtain a 4-bit SLS value. */
+ return ipa_rx_msg(asp, msg, fd & 0xf);
}
static int xua_cli_read_cb(struct osmo_stream_cli *conn)
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index ff27cf3..5a637b4 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -1133,10 +1133,10 @@ DEFUN(show_cs7_asp, show_cs7_asp_cmd,
llist_for_each_entry(asp, &inst->asp_list, list) {
if (asp->cfg.proto == OSMO_SS7_ASP_PROT_IPA && asp->cfg.remote.port == 0 && asp->server) {
- struct osmo_fd *ofd = osmo_stream_srv_get_ofd(asp->server);
+ int fd = osmo_stream_srv_get_fd(asp->server);
char hostbuf[64];
char portbuf[16];
- osmo_sock_get_ip_and_port(ofd->fd, hostbuf, sizeof(hostbuf),
+ osmo_sock_get_ip_and_port(fd, hostbuf, sizeof(hostbuf),
portbuf, sizeof(portbuf), false);
snprintf(buf, sizeof(buf), "%s:%s", hostbuf, portbuf);
} else
diff --git a/src/xua_asp_fsm.c b/src/xua_asp_fsm.c
index 0080497..2d81bc3 100644
--- a/src/xua_asp_fsm.c
+++ b/src/xua_asp_fsm.c
@@ -848,16 +848,16 @@ enum ipa_asp_fsm_t {
static int get_fd_from_iafp(struct ipa_asp_fsm_priv *iafp)
{
struct osmo_ss7_asp *asp = iafp->asp;
- struct osmo_fd *ofd;
+ int fd;
if (asp->server)
- ofd = osmo_stream_srv_get_ofd(asp->server);
+ fd = osmo_stream_srv_get_fd(asp->server);
else if (asp->client)
- ofd = osmo_stream_cli_get_ofd(asp->client);
+ fd = osmo_stream_cli_get_fd(asp->client);
else
return -1;
- return ofd->fd;
+ return fd;
}
/***************