diff --git a/TODO-RELEASE b/TODO-RELEASE index d0852fc..b7cb070 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 +libosmo-netif stream osmo_sock_init2_multiaddr() is used, requires libosmocore > 1.2.0 (to be released) diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index 3427df5..8fe2578 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -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)); diff --git a/src/stream.c b/src/stream.c index 9c4afec..0027537 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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;