pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/35235?usp=email )
Change subject: stream_cli: Fix opening sctp client socket if no local address set ......................................................................
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 TODO-RELEASE M src/stream_cli.c 2 files changed, 33 insertions(+), 4 deletions(-)
Approvals: Jenkins Builder: Verified osmith: Looks good to me, approved
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 @@ * \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: