From cd81de3c0acbb3d1b38ac7ca14650d00cdd4061b Mon Sep 17 00:00:00 2001 From: "Bruce A. Mah" Date: Wed, 9 Apr 2014 10:29:16 -0700 Subject: [PATCH] Rework detection / enabling of SCTP support. Rather than doing checks for platforms that we believe support SCTP, instead look for an indication (notably the presence of ) that it's supported. This makes the conditionals for SCTP more obvious. In addition, it opens up the possibility that SCTP might work on some new OS that's not FreeBSD or Linux. This change may force some additional build-time requirements on Linux, such as lksctp-tools-devel on CentOS / Fedora or libsctp-dev on Ubuntu. Committing this first cut for review and to enable testing on multiple platforms. So far this works correctly on Linux (SCTP support) and MacOS (no SCTP support). --- configure.ac | 4 ++++ src/config.h.in | 6 ++++++ src/iperf_api.c | 18 +++++++++++++----- src/iperf_api.h | 1 + src/iperf_error.c | 3 +++ src/iperf_sctp.c | 36 ++++++++++++++++++++++++++++++++++++ src/iperf_sctp.h | 7 +------ src/locale.c | 6 ++++-- 8 files changed, 68 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 6a2979f..60d0ac4 100644 --- a/configure.ac +++ b/configure.ac @@ -46,4 +46,8 @@ exit 1 # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST +# Check for SCTP support +AC_CHECK_HEADERS([netinet/sctp.h], + AC_DEFINE([HAVE_SCTP], [1], [Have SCTP support.])) + AC_OUTPUT([Makefile src/Makefile examples/Makefile]) diff --git a/src/config.h.in b/src/config.h.in index fd8dcc3..5c1ff0b 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -9,6 +9,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_SCTP_H + +/* Have SCTP support. */ +#undef HAVE_SCTP + /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H diff --git a/src/iperf_api.c b/src/iperf_api.c index e69c488..86f342f 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -40,12 +40,15 @@ #include #endif +#include "config.h" #include "net.h" #include "iperf.h" #include "iperf_api.h" #include "iperf_udp.h" #include "iperf_tcp.h" +#if defined(HAVE_SCTP) #include "iperf_sctp.h" +#endif /* HAVE_SCTP */ #include "timer.h" #include "cjson.h" @@ -570,7 +573,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) #if defined(linux) && defined(TCP_CONGESTION) {"linux-congestion", required_argument, NULL, 'C'}, #endif -#if defined(linux) || defined(__FreeBSD__) +#if defined(HAVE_SCTP) {"sctp", no_argument, NULL, OPT_SCTP}, #endif {"pidfile", required_argument, NULL, 'I'}, @@ -639,13 +642,13 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) client_flag = 1; break; case OPT_SCTP: -#if defined(linux) || defined(__FreeBSD__) +#if defined(HAVE_SCTP) set_protocol(test, Psctp); client_flag = 1; -#else /* linux */ +#else /* HAVE_SCTP */ i_errno = IEUNIMP; return -1; -#endif /* linux */ +#endif /* HAVE_SCTP */ break; case 'b': @@ -1555,7 +1558,10 @@ protocol_free(struct protocol *proto) int iperf_defaults(struct iperf_test *testp) { - struct protocol *tcp, *udp, *sctp; + struct protocol *tcp, *udp; +#if defined(HAVE_SCTP) + struct protocol *sctp; +#endif /* HAVE_SCTP */ testp->omit = OMIT; testp->duration = DURATION; @@ -1627,6 +1633,7 @@ iperf_defaults(struct iperf_test *testp) set_protocol(testp, Ptcp); +#if defined(HAVE_SCTP) sctp = protocol_new(); if (!sctp) { protocol_free(tcp); @@ -1644,6 +1651,7 @@ iperf_defaults(struct iperf_test *testp) sctp->init = iperf_sctp_init; SLIST_INSERT_AFTER(udp, sctp, protocols); +#endif /* HAVE_SCTP */ testp->on_new_stream = iperf_on_new_stream; testp->on_test_start = iperf_on_test_start; diff --git a/src/iperf_api.h b/src/iperf_api.h index d2f5dbb..ea5eb2c 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -255,6 +255,7 @@ enum { IEBURST = 15, // Invalid burst count. Maximum value = %dMAX_BURST IEENDCONDITIONS = 16, // Only one test end condition (-t, -n, -k) may be specified IELOGFILE = 17, // Can't open log file + IENOSCTP = 18, // No SCTP support available /* Test errors */ IENEWTEST = 100, // Unable to create a new test (check perror) IEINITTEST = 101, // Test initialization failed (check perror) diff --git a/src/iperf_error.c b/src/iperf_error.c index ea889f8..ef1d1ef 100644 --- a/src/iperf_error.c +++ b/src/iperf_error.c @@ -130,6 +130,9 @@ iperf_strerror(int i_errno) snprintf(errstr, len, "unable to open log file"); perr = 1; break; + case IENOSCTP: + snprintf(errstr, len, "no SCTP support available"); + break; case IENEWTEST: snprintf(errstr, len, "unable to create a new test"); perr = 1; diff --git a/src/iperf_sctp.c b/src/iperf_sctp.c index bb4c218..d14a7ab 100644 --- a/src/iperf_sctp.c +++ b/src/iperf_sctp.c @@ -20,6 +20,12 @@ #include #include +#include "config.h" + +#ifdef HAVE_NETINET_SCTP_H +#include +#endif /* HAVE_NETINET_SCTP_H */ + #include "iperf.h" #include "iperf_api.h" #include "iperf_sctp.h" @@ -34,6 +40,7 @@ int iperf_sctp_recv(struct iperf_stream *sp) { +#if defined(HAVE_SCTP) int r; r = Nread(sp->socket, sp->buffer, sp->settings->blksize, Psctp); @@ -44,6 +51,10 @@ iperf_sctp_recv(struct iperf_stream *sp) sp->result->bytes_received_this_interval += r; return r; +#else + i_errno = IENOSCTP; + return -1; +#endif /* HAVE_SCTP */ } @@ -54,6 +65,7 @@ iperf_sctp_recv(struct iperf_stream *sp) int iperf_sctp_send(struct iperf_stream *sp) { +#if defined(HAVE_SCTP) int r; r = Nwrite(sp->socket, sp->buffer, sp->settings->blksize, Psctp); @@ -64,6 +76,10 @@ iperf_sctp_send(struct iperf_stream *sp) sp->result->bytes_sent_this_interval += r; return r; +#else + i_errno = IENOSCTP; + return -1; +#endif /* HAVE_SCTP */ } @@ -75,6 +91,7 @@ iperf_sctp_send(struct iperf_stream *sp) int iperf_sctp_accept(struct iperf_test * test) { +#if defined(HAVE_SCTP) int s; signed char rbuf = ACCESS_DENIED; char cookie[COOKIE_SIZE]; @@ -102,6 +119,10 @@ iperf_sctp_accept(struct iperf_test * test) } return s; +#else + i_errno = IENOSCTP; + return -1; +#endif /* HAVE_SCTP */ } @@ -112,6 +133,7 @@ iperf_sctp_accept(struct iperf_test * test) int iperf_sctp_listen(struct iperf_test *test) { +#if defined(HAVE_SCTP) struct addrinfo hints, *res; char portstr[6]; int s, opt; @@ -173,6 +195,10 @@ iperf_sctp_listen(struct iperf_test *test) test->listener = s; return s; +#else + i_errno = IENOSCTP; + return -1; +#endif /* HAVE_SCTP */ } @@ -183,6 +209,7 @@ iperf_sctp_listen(struct iperf_test *test) int iperf_sctp_connect(struct iperf_test *test) { +#if defined(HAVE_SCTP) int s, opt; char portstr[6]; struct addrinfo hints, *local_res, *server_res; @@ -242,6 +269,10 @@ iperf_sctp_connect(struct iperf_test *test) } return s; +#else + i_errno = IENOSCTP; + return -1; +#endif /* HAVE_SCTP */ } @@ -249,6 +280,11 @@ iperf_sctp_connect(struct iperf_test *test) int iperf_sctp_init(struct iperf_test *test) { +#if defined(HAVE_SCTP) return 0; +#else + i_errno = IENOSCTP; + return -1; +#endif /* HAVE_SCTP */ } diff --git a/src/iperf_sctp.h b/src/iperf_sctp.h index 820d10e..3e624c6 100644 --- a/src/iperf_sctp.h +++ b/src/iperf_sctp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2011, The Regents of the University of California, + * Copyright (c) 2009-2014, The Regents of the University of California, * through Lawrence Berkeley National Laboratory (subject to receipt of any * required approvals from the U.S. Dept. of Energy). All rights reserved. * @@ -10,11 +10,6 @@ #ifndef IPERF_SCTP_H #define IPERF_SCTP_H - -#ifndef SCTP_DISABLE_FRAGMENTS -#define SCTP_DISABLE_FRAGMENTS 8 -#endif - /** * iperf_sctp_accept -- accepts a new SCTP connection * on sctp_listener_socket for SCTP data and param/result diff --git a/src/locale.c b/src/locale.c index cb58922..3d4eccf 100644 --- a/src/locale.c +++ b/src/locale.c @@ -53,6 +53,8 @@ #include "version.h" +#include "config.h" + #ifdef __cplusplus extern "C" { @@ -88,9 +90,9 @@ const char usage_longstr[] = "Usage: iperf [-s|-c host] [options]\n" " -I, --pidfile file write PID file\n" "Client specific:\n" " -c, --client run in client mode, connecting to \n" -#if defined(linux) || defined(__FreeBSD__) +#if defined(HAVE_SCTP) " --sctp use SCTP rather than TCP\n" -#endif +#endif /* HAVE_SCTP */ " -u, --udp use UDP rather than TCP\n" " -b, --bandwidth #[KMG][/#] target bandwidth in bits/sec\n" " (default %d Mbit/sec for UDP, unlimited for TCP)\n"