Change in libosmocore[master]: socket: Introduce API osmo_sock_init2_multiaddr()

2019-10-18 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15781 )

Change subject: socket: Introduce API osmo_sock_init2_multiaddr()
..

socket: Introduce API osmo_sock_init2_multiaddr()

This API will be used by libosmo-netif's osmo_stream for SCTP sockets,
which in turn will be used by libosmo-sccp to support multi-homed
connections.

Related: OS#3608
Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
---
M configure.ac
M debian/control
M include/osmocom/core/socket.h
M src/Makefile.am
M src/socket.c
5 files changed, 307 insertions(+), 2 deletions(-)

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



diff --git a/configure.ac b/configure.ac
index 39d232b..2f12d86 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,6 +100,17 @@

 AC_CHECK_FUNCS(clock_gettime localtime_r)

+old_LIBS=$LIBS
+AC_SEARCH_LIBS([sctp_bindx], [sctp], [
+   AC_DEFINE(HAVE_LIBSCTP, 1, [Define 1 to enable SCTP support])
+   AC_SUBST(HAVE_LIBSCTP, [1])
+   if test -n "$ac_lib"; then
+   AC_SUBST(LIBSCTP_LIBS, [-l$ac_lib])
+   fi
+   ], [
+   AC_MSG_WARN([sctp_bindx not found in searched libs])])
+LIBS=$old_LIBS
+
 AC_DEFUN([CHECK_TM_INCLUDES_TM_GMTOFF], [
   AC_CACHE_CHECK(
 [whether struct tm has tm_gmtoff member],
diff --git a/debian/control b/debian/control
index 07163da..6c9cfae 100644
--- a/debian/control
+++ b/debian/control
@@ -15,6 +15,7 @@
libpcsclite-dev,
pkg-config,
libtalloc-dev,
+   libsctp-dev,
python (>= 2.7.6)
 Standards-Version: 3.9.8
 Vcs-Git: git://git.osmocom.org/libosmocore.git
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 37b1eae..e26ca0d 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -36,6 +36,9 @@
 /*! use SO_REUSEADDR on UDP ports (required for multicast) */
 #define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)

+/*! maximum number of local or remote addresses supported by an osmo_sock 
instance */
+#define OSMO_SOCK_MAX_ADDRS 32
+
 int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
   const char *host, uint16_t port, unsigned int flags);

@@ -43,6 +46,10 @@
   const char *local_host, uint16_t local_port,
   const char *remote_host, uint16_t remote_port, unsigned int 
flags);

+int osmo_sock_init2_multiaddr(uint16_t family, uint16_t type, uint8_t proto,
+  const char **local_hosts, size_t local_hosts_cnt, uint16_t 
local_port,
+  const char **remote_hosts, size_t remote_hosts_cnt, uint16_t 
remote_port, unsigned int flags);
+
 int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
const char *host, uint16_t port, unsigned int flags);

diff --git a/src/Makefile.am b/src/Makefile.am
index 5f5f017..9943281 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@
 LIBVERSION=14:0:2

 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
-AM_CFLAGS = -Wall $(TALLOC_CFLAGS) $(PTHREAD_CFLAGS)
+AM_CFLAGS = -Wall $(TALLOC_CFLAGS) $(PTHREAD_CFLAGS) $(LIBSCTP_CFLAGS)

 if ENABLE_PSEUDOTALLOC
 AM_CPPFLAGS += -I$(top_srcdir)/src/pseudotalloc
@@ -12,7 +12,7 @@

 lib_LTLIBRARIES = libosmocore.la

-libosmocore_la_LIBADD = $(BACKTRACE_LIB) $(TALLOC_LIBS) $(LIBRARY_RT) 
$(PTHREAD_LIBS)
+libosmocore_la_LIBADD = $(BACKTRACE_LIB) $(TALLOC_LIBS) $(LIBRARY_RT) 
$(PTHREAD_LIBS) $(LIBSCTP_LIBS)
 libosmocore_la_SOURCES = context.c timer.c timer_gettimeofday.c 
timer_clockgettime.c \
 select.c signal.c msgb.c bits.c \
 bitvec.c bitcomp.c counter.c fsm.c \
diff --git a/src/socket.c b/src/socket.c
index ef3bb58..542c76e 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -53,6 +53,10 @@
 #include 
 #include 

+#ifdef HAVE_LIBSCTP
+#include 
+#endif
+
 static struct addrinfo *addrinfo_helper(uint16_t family, uint16_t type, 
uint8_t proto,
const char *host, uint16_t port, bool 
passive)
 {
@@ -96,6 +100,34 @@
return result;
 }

+/*! Retrieve an array of addrinfo with specified hints, one for each host in 
the hosts array.
+ *  \param[out] addrinfo array of addrinfo pointers, will be filled by the 
function on success.
+ * Its size must be at least the one of hosts.
+ *  \param[in] family Socket family like AF_INET, AF_INET6.
+ *  \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM.
+ *  \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP.
+ *  \param[in] hosts array of char pointers (strings) containing the addresses 
to query.
+ *  \param[in] host_cnt length of the hosts array (in items).
+ *  \param[in] port port number in host byte order.
+ *  \param[in] passive whether to include the AI_PASSIVE flag in getaddrinfo() 
hints.
+ *  \returns 0 is returned on success together 

Change in libosmocore[master]: socket: Introduce API osmo_sock_init2_multiaddr()

2019-10-18 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15781 )

Change subject: socket: Introduce API osmo_sock_init2_multiaddr()
..


Patch Set 3: Code-Review+2


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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Gerrit-Change-Number: 15781
Gerrit-PatchSet: 3
Gerrit-Owner: pespin 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: lynxis lazus 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Fri, 18 Oct 2019 09:21:47 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: socket: Introduce API osmo_sock_init2_multiaddr()

2019-10-15 Thread pespin
Hello laforge, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/libosmocore/+/15781

to look at the new patch set (#3).

Change subject: socket: Introduce API osmo_sock_init2_multiaddr()
..

socket: Introduce API osmo_sock_init2_multiaddr()

This API will be used by libosmo-netif's osmo_stream for SCTP sockets,
which in turn will be used by libosmo-sccp to support multi-homed
connections.

Related: OS#3608
Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
---
M configure.ac
M debian/control
M include/osmocom/core/socket.h
M src/Makefile.am
M src/socket.c
5 files changed, 307 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/81/15781/3
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15781
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Gerrit-Change-Number: 15781
Gerrit-PatchSet: 3
Gerrit-Owner: pespin 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-MessageType: newpatchset


Change in libosmocore[master]: socket: Introduce API osmo_sock_init2_multiaddr()

2019-10-15 Thread pespin
Hello laforge, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/libosmocore/+/15781

to look at the new patch set (#2).

Change subject: socket: Introduce API osmo_sock_init2_multiaddr()
..

socket: Introduce API osmo_sock_init2_multiaddr()

This API will be used by libosmo-netif's osmo_stream for SCTP sockets,
which in turn will be used by libosmo-sccp to support multi-homed
connections.

Related: OS#3608
Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
---
M configure.ac
M debian/control
M include/osmocom/core/socket.h
M src/Makefile.am
M src/socket.c
5 files changed, 307 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/81/15781/2
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15781
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Gerrit-Change-Number: 15781
Gerrit-PatchSet: 2
Gerrit-Owner: pespin 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-MessageType: newpatchset


Change in libosmocore[master]: socket: Introduce API osmo_sock_init2_multiaddr()

2019-10-14 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15781 )

Change subject: socket: Introduce API osmo_sock_init2_multiaddr()
..


Patch Set 1: Code-Review+1


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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Gerrit-Change-Number: 15781
Gerrit-PatchSet: 1
Gerrit-Owner: pespin 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Comment-Date: Mon, 14 Oct 2019 20:34:38 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: socket: Introduce API osmo_sock_init2_multiaddr()

2019-10-11 Thread pespin
pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15781 )


Change subject: socket: Introduce API osmo_sock_init2_multiaddr()
..

socket: Introduce API osmo_sock_init2_multiaddr()

This API will be used by libosmo-netif's osmo_stream for SCTP sockets,
which in turn will be used by libosmo-sccp to support multi-homed
connections.

Related: OS#3608
Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
---
M configure.ac
M include/osmocom/core/socket.h
M src/Makefile.am
M src/socket.c
4 files changed, 306 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/81/15781/1

diff --git a/configure.ac b/configure.ac
index 39d232b..2aefd2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,6 +100,17 @@

 AC_CHECK_FUNCS(clock_gettime localtime_r)

+old_LIBS=$LIBS
+AC_SEARCH_LIBS([sctp_bindx], [sctp], [
+   AC_DEFINE(HAVE_LIBSCTP, 1, [Define 1 to enable SCTP support])
+   AC_SUBST(HAVE_LIBSCTP, [1])
+   if test -n "$ac_lib"; then
+   AC_SUBST(LIBSCTP_LIBS, [-l$ac_lib])
+   fi
+   ], [
+   AC_MSG_ERROR([sctp_bindx not found in searched libs])])
+LIBS=$old_LIBS
+
 AC_DEFUN([CHECK_TM_INCLUDES_TM_GMTOFF], [
   AC_CACHE_CHECK(
 [whether struct tm has tm_gmtoff member],
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 37b1eae..e26ca0d 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -36,6 +36,9 @@
 /*! use SO_REUSEADDR on UDP ports (required for multicast) */
 #define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)

+/*! maximum number of local or remote addresses supported by an osmo_sock 
instance */
+#define OSMO_SOCK_MAX_ADDRS 32
+
 int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
   const char *host, uint16_t port, unsigned int flags);

@@ -43,6 +46,10 @@
   const char *local_host, uint16_t local_port,
   const char *remote_host, uint16_t remote_port, unsigned int 
flags);

+int osmo_sock_init2_multiaddr(uint16_t family, uint16_t type, uint8_t proto,
+  const char **local_hosts, size_t local_hosts_cnt, uint16_t 
local_port,
+  const char **remote_hosts, size_t remote_hosts_cnt, uint16_t 
remote_port, unsigned int flags);
+
 int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
const char *host, uint16_t port, unsigned int flags);

diff --git a/src/Makefile.am b/src/Makefile.am
index 5f5f017..9943281 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@
 LIBVERSION=14:0:2

 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
-AM_CFLAGS = -Wall $(TALLOC_CFLAGS) $(PTHREAD_CFLAGS)
+AM_CFLAGS = -Wall $(TALLOC_CFLAGS) $(PTHREAD_CFLAGS) $(LIBSCTP_CFLAGS)

 if ENABLE_PSEUDOTALLOC
 AM_CPPFLAGS += -I$(top_srcdir)/src/pseudotalloc
@@ -12,7 +12,7 @@

 lib_LTLIBRARIES = libosmocore.la

-libosmocore_la_LIBADD = $(BACKTRACE_LIB) $(TALLOC_LIBS) $(LIBRARY_RT) 
$(PTHREAD_LIBS)
+libosmocore_la_LIBADD = $(BACKTRACE_LIB) $(TALLOC_LIBS) $(LIBRARY_RT) 
$(PTHREAD_LIBS) $(LIBSCTP_LIBS)
 libosmocore_la_SOURCES = context.c timer.c timer_gettimeofday.c 
timer_clockgettime.c \
 select.c signal.c msgb.c bits.c \
 bitvec.c bitcomp.c counter.c fsm.c \
diff --git a/src/socket.c b/src/socket.c
index ef3bb58..542c76e 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -53,6 +53,10 @@
 #include 
 #include 

+#ifdef HAVE_LIBSCTP
+#include 
+#endif
+
 static struct addrinfo *addrinfo_helper(uint16_t family, uint16_t type, 
uint8_t proto,
const char *host, uint16_t port, bool 
passive)
 {
@@ -96,6 +100,34 @@
return result;
 }

+/*! Retrieve an array of addrinfo with specified hints, one for each host in 
the hosts array.
+ *  \param[out] addrinfo array of addrinfo pointers, will be filled by the 
function on success.
+ * Its size must be at least the one of hosts.
+ *  \param[in] family Socket family like AF_INET, AF_INET6.
+ *  \param[in] type Socket type like SOCK_DGRAM, SOCK_STREAM.
+ *  \param[in] proto Protocol like IPPROTO_TCP, IPPROTO_UDP.
+ *  \param[in] hosts array of char pointers (strings) containing the addresses 
to query.
+ *  \param[in] host_cnt length of the hosts array (in items).
+ *  \param[in] port port number in host byte order.
+ *  \param[in] passive whether to include the AI_PASSIVE flag in getaddrinfo() 
hints.
+ *  \returns 0 is returned on success together with a filled addrinfo array; 
negative on error
+ */
+static int addrinfo_helper_multi(struct addrinfo **addrinfo, uint16_t family, 
uint16_t type, uint8_t proto,
+   const char **hosts, size_t host_cnt, 
uint16_t port, bool passive)
+{
+   int i, j;
+
+   for (i = 0; i < host_cnt; i++) {
+   addrinfo[i] =