diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-01-09 13:27:01 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-01-09 14:10:20 +0100 |
commit | d1b1ff77a6bc2f70366c5d2f5079c70f5eae52a0 (patch) | |
tree | d047bf43cc6a46ed6e693e6a6c456249f77ed850 | |
parent | c633f54a3cdc95d6d1130be6cc5dc930c104beac (diff) |
configure.ac: Introduce --{enable,disable}-libsctp configure flag
Similar to what we do in libosmocore already, we want to
deterministically enable or disable support for the feature without
having into account if the system has a libsctp. If libsctp is missing
and support is enabled, then fail.
Extra checks are also added:
* Check netinet/sctp.h header
* Check libosmocore was built with libsctp support (API
osmo_sock_init2_multiaddr() we require).
* In stream.c make sure it can be built without HAVE_LIBSCTP, and that
set_addrs() fails for more than 1 address (since that feature is only
supported through osmo_sock_init2_multiaddrs()).
Change-Id: I4b3e1f1894f13ac1175a71a5139c02a2633be26d
-rw-r--r-- | configure.ac | 28 | ||||
-rw-r--r-- | src/stream.c | 26 |
2 files changed, 38 insertions, 16 deletions
diff --git a/configure.ac b/configure.ac index 7af10ec..a96fb70 100644 --- a/configure.ac +++ b/configure.ac @@ -87,16 +87,24 @@ PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.3.0) dnl FIXME: We depend on libosmoabis by now until we can move LAPD code here PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.6.0) -old_LIBS=$LIBS -AC_SEARCH_LIBS([sctp_send], [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_send not found in searched libs])]) -LIBS=$old_LIBS +AC_ARG_ENABLE([libsctp], [AS_HELP_STRING([--disable-libsctp], [Do not enable socket multiaddr APIs requiring libsctp])], + [ENABLE_LIBSCTP=$enableval], [ENABLE_LIBSCTP="yes"]) +AM_CONDITIONAL(ENABLE_LIBSCTP, test x"$ENABLE_LIBSCTP" = x"yes") +AS_IF([test "x$ENABLE_LIBSCTP" = "xyes"], [ + AC_CHECK_HEADERS(netinet/sctp.h,,AC_MSG_ERROR(netinet/sctp.h not found)) + old_LIBS=$LIBS + AC_CHECK_LIB(osmocore, osmo_sock_init2_multiaddr,, AC_MSG_ERROR(libosmocore built without libsctp support), $LIBOSMOCORE_LIBS) + LIBS=$old_LIBS + AC_SEARCH_LIBS([sctp_send], [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_send not found in searched libs])]) + LIBS=$old_LIBS +]) AC_CHECK_HEADERS(dahdi/user.h,,AC_MSG_WARN(DAHDI input driver will not be built)) diff --git a/src/stream.c b/src/stream.c index 744a904..537fd28 100644 --- a/src/stream.c +++ b/src/stream.c @@ -106,9 +106,11 @@ static int setsockopt_nodelay(int fd, int proto, int on) int rc; switch (proto) { +#ifdef HAVE_LIBSCTP case IPPROTO_SCTP: rc = setsockopt(fd, IPPROTO_SCTP, SCTP_NODELAY, &on, sizeof(on)); break; +#endif case IPPROTO_TCP: rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); break; @@ -143,15 +145,21 @@ static const struct value_string stream_cli_state_names[] = { #define OSMO_STREAM_CLI_F_RECONF (1 << 0) #define OSMO_STREAM_CLI_F_NODELAY (1 << 1) +#ifdef HAVE_LIBSCTP +#define OSMO_STREAM_MAX_ADDRS OSMO_SOCK_MAX_ADDRS +#else +#define OSMO_STREAM_MAX_ADDRS 1 +#endif + struct osmo_stream_cli { struct osmo_fd ofd; struct llist_head tx_queue; struct osmo_timer_list timer; enum osmo_stream_cli_state state; - char *addr[OSMO_SOCK_MAX_ADDRS]; + char *addr[OSMO_STREAM_MAX_ADDRS]; uint8_t addrcnt; uint16_t port; - char *local_addr[OSMO_SOCK_MAX_ADDRS]; + char *local_addr[OSMO_STREAM_MAX_ADDRS]; uint8_t local_addrcnt; uint16_t local_port; uint16_t proto; @@ -369,7 +377,7 @@ int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, const char **addr, si { int i = 0; - if (addrcnt > OSMO_SOCK_MAX_ADDRS) + if (addrcnt > OSMO_STREAM_MAX_ADDRS) return -EINVAL; for (; i < addrcnt; i++) @@ -426,7 +434,7 @@ int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, const char **ad { int i = 0; - if (addrcnt > OSMO_SOCK_MAX_ADDRS) + if (addrcnt > OSMO_STREAM_MAX_ADDRS) return -EINVAL; for (; i < addrcnt; i++) @@ -554,12 +562,14 @@ int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) cli->flags &= ~OSMO_STREAM_CLI_F_RECONF; switch (cli->proto) { +#ifdef HAVE_LIBSCTP 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; +#endif default: ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto, cli->local_addr[0], cli->local_port, @@ -623,12 +633,14 @@ int osmo_stream_cli_open(struct osmo_stream_cli *cli) switch (cli->proto) { +#ifdef HAVE_LIBSCTP 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; +#endif default: ret = osmo_sock_init2(AF_INET, SOCK_STREAM, cli->proto, cli->local_addr[0], cli->local_port, @@ -718,7 +730,7 @@ int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg) struct osmo_stream_srv_link { struct osmo_fd ofd; - char *addr[OSMO_SOCK_MAX_ADDRS]; + char *addr[OSMO_STREAM_MAX_ADDRS]; uint8_t addrcnt; uint16_t port; uint16_t proto; @@ -830,7 +842,7 @@ int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char { int i = 0; - if (addrcnt > OSMO_SOCK_MAX_ADDRS) + if (addrcnt > OSMO_STREAM_MAX_ADDRS) return -EINVAL; for (; i < addrcnt; i++) @@ -950,11 +962,13 @@ int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) link->flags &= ~OSMO_STREAM_SRV_F_RECONF; switch (link->proto) { +#ifdef HAVE_LIBSCTP 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; +#endif default: ret = osmo_sock_init(AF_INET, SOCK_STREAM, link->proto, link->addr[0], link->port, OSMO_SOCK_F_BIND); |