pespin has uploaded this change for review.
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
---
M src/stream_cli.c
1 file changed, 32 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/35/35235/1
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 @@
* \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 @@
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:
To view, visit change 35235. To unsubscribe, or for help writing mail filters, visit settings.