aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-12-05 17:00:24 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2023-12-06 13:46:28 +0100
commita15d8f7f20fefca21c849701b3b1b4d0dd90e872 (patch)
tree83d701cc84a1aaa6d6bbdc80a1719a45ae2769b1
parent5ccee1e1b115a5b39e6bad7b7d45d5188f885b7d (diff)
stream_cli: Fix opening sctp client socket if no local address set
Properly call osmo_sock_init2_multiaddr2() to use default binding address if user of osmo_stream_cli didn't set one on the object through the API. osmo_sock_init2_multiaddr2() was also borken under that scenario until recently (see Depends below). Until now, users of osmo_stream for SCTP (mainly libosmo-sccp) relied on always setting a proper local address to overcome this limitation. Depends: libosmocore.git Change-Id I2641fbaca6f477404b094dbc53c0c1a3dd3fd2fd Related: OS#6279 Change-Id: I0d9d0e48690c915f7b51ad09f452e551e01368b5
-rw-r--r--TODO-RELEASE1
-rw-r--r--src/stream_cli.c17
2 files changed, 14 insertions, 4 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index d0852fc..2346129 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
# 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 working osmo_sock_init2_multiaddr2() without setting flag OSMO_SOCK_F_BIND \ No newline at end of file
diff --git a/src/stream_cli.c b/src/stream_cli.c
index 1e7ebeb..4f2963d 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -838,7 +838,9 @@ void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay)
* \return negative on error, 0 on success */
int osmo_stream_cli_open(struct osmo_stream_cli *cli)
{
- int ret, fd = -1;
+ int ret, flags;
+ int fd = -1;
+ unsigned int local_addrcnt;
/* we are reconfiguring this socket, close existing first. */
if ((cli->flags & OSMO_STREAM_CLI_F_RECONF) && osmo_stream_cli_get_fd(cli) >= 0)
@@ -856,11 +858,18 @@ int osmo_stream_cli_open(struct osmo_stream_cli *cli)
switch (cli->proto) {
#ifdef HAVE_LIBSCTP
case IPPROTO_SCTP:
+ local_addrcnt = cli->local_addrcnt;
+ flags = OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_NONBLOCK;
+ if (cli->local_addrcnt > 0 || cli->local_port > 0) { /* explicit bind required? */
+ flags |= OSMO_SOCK_F_BIND;
+ /* If no local addr configured, use local_addr[0]=NULL by default when creating the socket. */
+ if (cli->local_addrcnt == 0)
+ local_addrcnt = 1;
+ }
ret = osmo_sock_init2_multiaddr2(cli->sk_domain, cli->sk_type, cli->proto,
- (const char **)cli->local_addr, cli->local_addrcnt, cli->local_port,
+ (const char **)cli->local_addr, local_addrcnt, cli->local_port,
(const char **)cli->addr, cli->addrcnt, cli->port,
- OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK,
- &cli->ma_pars);
+ flags, &cli->ma_pars);
break;
#endif
default: