stream: osmo_stream_srv_link: Support setting multiple addr

This API will be later used to set multiple addresses for SCTP sockets.

Depends: libosmocore.git Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Related: OS#3608
Change-Id: I0fe62f518e195db4e34f3b0ad1762bb57ba9d92a
This commit is contained in:
Pau Espin 2019-10-10 20:34:29 +02:00
parent c25285f40e
commit f254ef80f2
3 changed files with 39 additions and 4 deletions

View File

@ -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
libosmo-netif stream osmo_sock_init2_multiaddr() is used, requires libosmocore > 1.2.0 (to be released)

View File

@ -22,6 +22,7 @@ void osmo_stream_srv_link_destroy(struct osmo_stream_srv_link *link);
void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay);
void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr);
int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt);
void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port);
void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto);
void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)(struct osmo_stream_srv_link *link, int fd));

View File

@ -647,7 +647,8 @@ int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg)
struct osmo_stream_srv_link {
struct osmo_fd ofd;
char *addr;
char *addr[OSMO_SOCK_MAX_ADDRS];
uint8_t addrcnt;
uint16_t port;
uint16_t proto;
int (*accept_cb)(struct osmo_stream_srv_link *srv, int fd);
@ -745,8 +746,32 @@ void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool no
void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link,
const char *addr)
{
osmo_talloc_replace_string(link, &link->addr, addr);
osmo_stream_srv_link_set_addrs(link, &addr, 1);
}
/*! \brief Set the local address set to which we bind.
* Useful for protocols allowing bind on more than one address (such as SCTP)
* \param[in] link Stream Server Link to modify
* \param[in] addr Local IP address
* \return negative on error, 0 on success
*/
int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt)
{
int i = 0;
if (addrcnt > OSMO_SOCK_MAX_ADDRS)
return -EINVAL;
for (; i < addrcnt; i++)
osmo_talloc_replace_string(link, &link->addr[i], addr[i]);
for (; i < link->addrcnt; i++) {
talloc_free(link->addr[i]);
link->addr[i] = NULL;
}
link->addrcnt = addrcnt;
link->flags |= OSMO_STREAM_SRV_F_RECONF;
return 0;
}
/*! \brief Set the local port number to which we bind
@ -853,8 +878,16 @@ int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link)
link->flags &= ~OSMO_STREAM_SRV_F_RECONF;
ret = osmo_sock_init(AF_INET, SOCK_STREAM, link->proto,
link->addr, link->port, OSMO_SOCK_F_BIND);
switch (link->proto) {
case IPPROTO_SCTP:
ret = osmo_sock_init2_multiaddr(AF_INET, SOCK_STREAM, link->proto,
(const char **)link->addr, link->addrcnt, link->port,
NULL, 0, 0, OSMO_SOCK_F_BIND);
break;
default:
ret = osmo_sock_init(AF_INET, SOCK_STREAM, link->proto,
link->addr[0], link->port, OSMO_SOCK_F_BIND);
}
if (ret < 0)
return ret;