lib: Support non-blocking sctp_connectx() calls

1: I decided to keep the previous "new" sctp_connectx() implementation,
because a: it costs nothing, and b: some very recent programs may rely
on the broken behaviour.

2: The new-new sctp_connectx() tries the new method first. If it fails
due to ENOPROTOOPT (old kernel) then it falls back to the old method first, but
only if it is safe to do so (blocking socket, or assoc_id not returned)

3: (note of users of this feature): If a non-blocking connect fails
quickly then a new call to sctp_connectx() may return an identical association
id becaue the ID has been freed up already.

Additional slight code clean-up.

Signed-off-by: Ivan Skytte Jørgensen <isj-sctp@i1.dk>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
lib: Fix the new connectx api to prefent SEGFAULTS

The new version connectx() that supports non-blocking sockets
fails the regression tests due to additional allocations that
it performes.  It can also segfault as it attempts to copy
addresses from the user provided buffer into a newly allocated
buffer.  To prevent that, we change the api to remove allocations
and pass the user-allocated address buffer unchanged to the kernel.
The api uses sctp_getadds_old structure, whete assoc_id is used
to return the association id, the addr_num is used to convey the
length of the address buffer to the kernel and addrs points
to the user-allocated addrs array the the library now passed on
as is.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
API: Add SCTP_SACK_IMMEDIATELY defintion.
api: SCTP_DELAYED_SACK typo fix

According to the api draft, the socket option for setting the
delayed sack timer should be called SCTP_DELAYED_SACK and not
SCTP_DELAYED_ACK.
Added a new define for SCTP_DELAYED_SACK (SCTP_DELAYED_ACK is not
removed to maintain compatibility with existing applications).

Signed-off-by: Andrei Pelinescu-Onciul <andrei@iptel.org>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
api:  Remove the old/obsolete getaddrs interfaces.

The new kernel has removed the 5 year old interfaces for
the 64-bit unsafe get_[l|p]addr interfaces.  Remove
them from the user library as well.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
api: Remove the sctp option enumerator

The sctp_optname enumerator is actually getting in the way as
we try to deprecate and remove really old options, because removing
items from the enum breaks binary compatibility with the kernel.
As a result, we do not gain any benefits from the enumerator, but
in fact get obfuscation of option values.  Now mirror the kernel
change and turn the enum into a defined list with specific values.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
sctp_darn: add inter command heartbeat for user initiated heartbeat

Add inter command heartbeat to sctp_darn, which is used for
request a user initiated heartbeat to be made immediately.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
sctp_test: add -B option and -C option for specifying addresses

This patch add -B option and -C option for specifying addresses.
Copy from sctp_dran.

-B option add the specified address(es) as additional bind
addresses of the local socket. Multiple addresses can be
specified by using this argument multiple times. For
example, '-B 10.0.0.1 -B 20.0.0.2'.

-C option use the specified address(es) for connection to the
peer socket. Multiple addresses can be specified by using this
argument multiple times. For example, '-C 10.0.0.1 -C 20.0.0.2'.
This option is incompatible with the -h option.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
sctp_test: add -O option for specifying live time of messages

This patch add -O option to sctp_test for specifying live
time of messages. Use for PRSCTP test.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
sctp_send: fix msg_control data corruption

The byte array outcmsg is allocated on the stack within the if-block
that test for a valif sctp_sndrcvinfo structure. There, it is assigned
to outmsg.msg_control, which is later on after leaving the if-block
passed to sendmsg. With this minimal example, the following is
happening:

int main(void)
{
	int fd;
	struct sctp_sndrcvinfo sndinfo;

	fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
	assert(fd > 0);

	sctp_send(fd, "bla", strlen("bla") + 1, &sndinfo, 0);

	return 0;
}

strace ./a.out before this patch:

  sendmsg(3, {msg_name(0)=NULL, msg_iov(1)=[{"bla\0", 4}],
          msg_controllen=48, {cmsg_len=3364590592, cmsg_level=0x4003e8
          /* SOL_??? */, cmsg_type=, ...}, msg_flags=0}, 0)

strace ./a.out after this patch:

  sendmsg(3, {msg_name(0)=NULL, msg_iov(1)=[{"bla\0", 4}],
          msg_controllen=48, {cmsg_len=48, cmsg_level=0x84 /* SOL_??? */,
                              cmsg_type=, ...}, msg_flags=0}, 0)

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>