This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
pespin gerrit-no-reply at lists.osmocom.orgpespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/15783 )
Change subject: stream: osmo_stream_cli: Support setting multiple addr
......................................................................
stream: osmo_stream_cli: 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: I09f0d989f2309abdeb304fe570355abed2cd107b
---
M include/osmocom/netif/stream.h
M src/stream.c
2 files changed, 85 insertions(+), 12 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/83/15783/1
diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index 8fe2578..331dec1 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -55,9 +55,11 @@
void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay);
void osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr);
+int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
void osmo_stream_cli_set_port(struct osmo_stream_cli *cli, uint16_t port);
void osmo_stream_cli_set_proto(struct osmo_stream_cli *cli, uint16_t proto);
void osmo_stream_cli_set_local_addr(struct osmo_stream_cli *cli, const char *addr);
+int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
void osmo_stream_cli_set_local_port(struct osmo_stream_cli *cli, uint16_t port);
void osmo_stream_cli_set_data(struct osmo_stream_cli *cli, void *data);
void osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout);
diff --git a/src/stream.c b/src/stream.c
index 0027537..b7e5c3c 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -148,9 +148,11 @@
struct llist_head tx_queue;
struct osmo_timer_list timer;
enum osmo_stream_cli_state state;
- char *addr;
+ char *addr[OSMO_SOCK_MAX_ADDRS];
+ uint8_t addrcnt;
uint16_t port;
- char *local_addr;
+ char *local_addr[OSMO_SOCK_MAX_ADDRS];
+ uint8_t local_addrcnt;
uint16_t local_port;
uint16_t proto;
int (*connect_cb)(struct osmo_stream_cli *srv);
@@ -354,8 +356,32 @@
void
osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr)
{
- osmo_talloc_replace_string(cli, &cli->addr, addr);
+ osmo_stream_cli_set_addrs(cli, &addr, 1);
+}
+
+/*! \brief Set the remote address set to which we connect.
+ * Useful for protocols allowing connecting to more than one address (such as SCTP)
+ * \param[in] cli Stream Client to modify
+ * \param[in] addr Remote IP address set
+ * \return negative on error, 0 on success
+ */
+int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, 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(cli, &cli->addr[i], addr[i]);
+ for (; i < cli->addrcnt; i++) {
+ talloc_free(cli->addr[i]);
+ cli->addr[i] = NULL;
+ }
+
+ cli->addrcnt = addrcnt;
cli->flags |= OSMO_STREAM_CLI_F_RECONF;
+ return 0;
}
/*! \brief Set the remote port number to which we connect
@@ -387,8 +413,32 @@
void
osmo_stream_cli_set_local_addr(struct osmo_stream_cli *cli, const char *addr)
{
- osmo_talloc_replace_string(cli, &cli->local_addr, addr);
+ osmo_stream_cli_set_local_addrs(cli, &addr, 1);
+}
+
+/*! \brief Set the local address set to which we connect.
+ * Useful for protocols allowing bind to more than one address (such as SCTP)
+ * \param[in] cli Stream Client to modify
+ * \param[in] addr Local IP address set
+ * \return negative on error, 0 on success
+ */
+int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, 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(cli, &cli->local_addr[i], addr[i]);
+ for (; i < cli->local_addrcnt; i++) {
+ talloc_free(cli->local_addr[i]);
+ cli->local_addr[i] = NULL;
+ }
+
+ cli->local_addrcnt = addrcnt;
cli->flags |= OSMO_STREAM_CLI_F_RECONF;
+ return 0;
}
/*! \brief Set the protocol for the stream client socket
@@ -503,10 +553,20 @@
cli->flags &= ~OSMO_STREAM_CLI_F_RECONF;
- ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto,
- cli->local_addr, cli->local_port,
- cli->addr, cli->port,
- OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
+ switch (cli->proto) {
+ case IPPROTO_SCTP:
+ ret = osmo_sock_init2_multiaddr(AF_INET, SOCK_STREAM, cli->proto,
+ (const char **)cli->local_addr, cli->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);
+ break;
+ default:
+ ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto,
+ cli->local_addr[0], cli->local_port,
+ cli->addr[0], cli->port,
+ OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
+ }
+
if (ret < 0) {
if (reconnect)
osmo_stream_cli_reconnect(cli);
@@ -561,10 +621,21 @@
cli->flags &= ~OSMO_STREAM_CLI_F_RECONF;
- ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto,
- cli->local_addr, cli->local_port,
- cli->addr, cli->port,
- OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
+
+ switch (cli->proto) {
+ case IPPROTO_SCTP:
+ ret = osmo_sock_init2_multiaddr(AF_INET, SOCK_STREAM, cli->proto,
+ (const char **)cli->local_addr, cli->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);
+ break;
+ default:
+ ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto,
+ cli->local_addr[0], cli->local_port,
+ cli->addr[0], cli->port,
+ OSMO_SOCK_F_CONNECT|OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
+ }
+
if (ret < 0) {
osmo_stream_cli_reconnect(cli);
return ret;
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/15783
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I09f0d989f2309abdeb304fe570355abed2cd107b
Gerrit-Change-Number: 15783
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191011/04b0d469/attachment.htm>