Change in libosmo-netif[master]: stream: osmo_stream_srv_link: Support setting multiple addr

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/.

laforge gerrit-no-reply at lists.osmocom.org
Fri Oct 18 09:23:30 UTC 2019


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/15782 )

Change subject: stream: osmo_stream_srv_link: Support setting multiple addr
......................................................................

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
---
M TODO-RELEASE
M include/osmocom/netif/stream.h
M src/stream.c
3 files changed, 39 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



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_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 @@
 
 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_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 @@
 
 	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;
 

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/15782
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I0fe62f518e195db4e34f3b0ad1762bb57ba9d92a
Gerrit-Change-Number: 15782
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191018/1ccff484/attachment.htm>


More information about the gerrit-log mailing list