├── .gitignore ├── .travis.yml ├── .travis ├── linux-build.sh └── linux-covscan.sh ├── AUTHORS ├── COPYING ├── COPYING.lib ├── ChangeLog ├── INSTALL ├── Makefile.am ├── Makefile.dirs ├── Makefile.rules ├── Makefile.vars ├── NEWS ├── README ├── ROADMAP ├── bin ├── .gitignore ├── Makefile.am └── aaaa ├── bootstrap ├── configure.ac ├── doc ├── Makefile.am ├── draft-stewart-tsvwg-sctpipv6-00.txt ├── draft-stewart-tsvwg-sctpscore-01.txt ├── ols.sty ├── ols.tex ├── random_notes.txt ├── rfc2960.txt ├── rfc3257.txt ├── rfc3286.txt ├── rfc3309.txt ├── rfc3554.txt ├── rfc3758.txt ├── rfc3873.txt ├── rfc4460.txt ├── rfc4820.txt ├── rfc4895.txt ├── rfc4960.txt ├── rfc5061.txt ├── rfc5062.txt ├── rfc6458.txt ├── states.txt ├── style_guide.txt ├── template.c └── what_we_were_doing.txt ├── libsctp.pc.in ├── lksctp-tools.spec.in ├── m4 ├── .gitignore └── sctp.m4 ├── man ├── Makefile.am ├── sctp.7 ├── sctp_bindx.3 ├── sctp_connectx.3 ├── sctp_getladdrs.3 ├── sctp_getpaddrs.3 ├── sctp_opt_info.3 ├── sctp_peeloff.3 ├── sctp_recvmsg.3 ├── sctp_recvv.3 ├── sctp_send.3 ├── sctp_sendmsg.3 └── sctp_sendv.3 ├── src ├── Makefile.am ├── apps │ ├── .gitignore │ ├── Makefile.am │ ├── bindx_test.c │ ├── myftp.c │ ├── nagle_rcv.c │ ├── nagle_snd.c │ ├── peel_client.c │ ├── peel_server.c │ ├── sctp_darn.c │ ├── sctp_darn.h │ ├── sctp_status.c │ ├── sctp_test.c │ └── sctp_xconnect.c ├── func_tests │ ├── .gitignore │ ├── Makefile.am │ ├── test_1_to_1_accept_close.c │ ├── test_1_to_1_addrs.c │ ├── test_1_to_1_connect.c │ ├── test_1_to_1_connectx.c │ ├── test_1_to_1_events.c │ ├── test_1_to_1_initmsg_connect.c │ ├── test_1_to_1_nonblock.c │ ├── test_1_to_1_recvfrom.c │ ├── test_1_to_1_recvmsg.c │ ├── test_1_to_1_rtoinfo.c │ ├── test_1_to_1_send.c │ ├── test_1_to_1_sendmsg.c │ ├── test_1_to_1_sendto.c │ ├── test_1_to_1_shutdown.c │ ├── test_1_to_1_socket_bind_listen.c │ ├── test_1_to_1_sockopt.c │ ├── test_1_to_1_threads.c │ ├── test_assoc_abort.c │ ├── test_assoc_shutdown.c │ ├── test_autoclose.c │ ├── test_basic.c │ ├── test_connect.c │ ├── test_connectx.c │ ├── test_fragments.c │ ├── test_getname.c │ ├── test_inaddr_any.c │ ├── test_interleave.c │ ├── test_peeloff.c │ ├── test_re_conf.c │ ├── test_recvmsg.c │ ├── test_sctp_sendrecvmsg.c │ ├── test_sctp_sendvrecvv.c │ ├── test_sockopt.c │ ├── test_tcp_style.c │ └── test_timetolive.c ├── include │ ├── Makefile.am │ └── netinet │ │ ├── Makefile.am │ │ └── sctp.h.in ├── lib │ ├── Makefile.am │ ├── Versions.map │ ├── addrs.c │ ├── bindx.c │ ├── connectx.c │ ├── opt_info.c │ ├── peeloff.c │ ├── recvmsg.c │ └── sendmsg.c ├── testlib │ ├── Makefile.am │ ├── sctputil.c │ └── sctputil.h └── withsctp │ ├── .gitignore │ ├── Makefile.am │ ├── README │ ├── checksctp.c │ ├── notes.txt │ ├── sctp_bind.c │ ├── sctp_load_libs.c │ ├── sctp_socket.c │ ├── sctp_socket.h │ ├── sctp_sockopt.c │ └── withsctp.in └── stamp-h.in /.gitignore: -------------------------------------------------------------------------------- 1 | aclocal.m4 2 | config.guess 3 | config.log 4 | config.status 5 | config.sub 6 | configure 7 | Makefile.in 8 | Makefile 9 | config.h 10 | config.h.in 11 | libsctp.pc 12 | libtool 13 | lksctp-tools.spec 14 | stamp-h1 15 | *.deps/ 16 | *.libs/ 17 | autom4te.cache/ 18 | *.la 19 | *.lo 20 | *.o 21 | tags 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | addons: 3 | apt: 4 | packages: 5 | - libelf-dev 6 | script: 7 | - ./.travis/linux-build.sh 8 | env: 9 | global: 10 | # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created 11 | # via the "travis encrypt" command using the project repo's public key 12 | - secure: "JuWc37fLUp36CB7kvmRvAE49cAuX3nxh8FmpcAHUFeefg2Z6ce+vBt5IdFW6dQgdoks35RbzkitUJwdcFiMggrN7jqs/ubIZkKeFzy4PP5oefU9L/w7z9bqSk+nolmA+sy/i6P6Yz7FHrGyXUhtZXnbsX/mQKclzsio7n22L+NDHVs4yUaLGmYPr1OvXcoHUPncuD7PHZcZzI3kKt6lUt2JAkacNUuUEIxQDxkL4gnoX5+OVG75twi0WD7r0vCGEGSMhHZ9y/7qi5Gx6xd5JVBkGVrXbZZtiZrtM1h0OD3Wn9B7ti5VOnWCQuuuxe49t5qKBjO6cC8Bz/2ktSIgf/WWdf4If2dRPyuJT36RqwmBbCJSqh4+qDRq0cP7Gb9zHwuz5kA3vpeBlx1l1oSF3CI7ZK7WtjetrvlrJ/SiLcuMRnnFgaUCNTyT5d4k1Dvxhlt/YJKxLVMualTUwcVZJEWDs07Sju3ljGkifEC3zQOoaOhVHKw/WDotIRW/HNGrzSblHV25hWKdvqIwcVTKGVbq7G/vJzxtpfjYj/t8gwlP31vWiv5/RdBbDk6DrV2/Wq+OSf8i/WHuTKTVjA9abV5LyGemEe0u/oJcRlUupN5UVLfCAozz/6GR6A99A88CoUijvxA5rvEEpQyYZnwjXCUP05iy6QBYD3VnLbg1pI3g=" 13 | matrix: 14 | - KERNEL="" 15 | compiler: 16 | - gcc 17 | - clang 18 | 19 | matrix: 20 | include: 21 | - os: linux 22 | addons: 23 | apt: 24 | sources: 25 | - ubuntu-toolchain-r-test 26 | packages: 27 | - libelf-dev 28 | - g++-4.9 29 | env: 30 | - MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9" 31 | 32 | - os: linux 33 | addons: 34 | apt: 35 | sources: 36 | - ubuntu-toolchain-r-test 37 | packages: 38 | - libelf-dev 39 | - g++-5 40 | env: 41 | - MATRIX_EVAL="CC=gcc-5 && CXX=g++-5" 42 | 43 | - os: linux 44 | addons: 45 | apt: 46 | sources: 47 | - ubuntu-toolchain-r-test 48 | packages: 49 | - libelf-dev 50 | - g++-6 51 | env: 52 | - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6" 53 | 54 | - os: linux 55 | addons: 56 | apt: 57 | sources: 58 | - ubuntu-toolchain-r-test 59 | packages: 60 | - libelf-dev 61 | - g++-7 62 | env: 63 | - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" 64 | 65 | # works on Trusty 66 | - os: linux 67 | addons: 68 | apt: 69 | sources: 70 | - llvm-toolchain-trusty-3.9 71 | packages: 72 | - libelf-dev 73 | - clang-3.9 74 | env: 75 | - MATRIX_EVAL="CC=clang-3.9 && CXX=clang++-3.9" 76 | 77 | # works on Trusty 78 | - os: linux 79 | addons: 80 | apt: 81 | sources: 82 | - llvm-toolchain-trusty-4.0 83 | packages: 84 | - libelf-dev 85 | - clang-4.0 86 | env: 87 | - MATRIX_EVAL="CC=clang-4.0 && CXX=clang++-4.0" 88 | 89 | # works on Trusty 90 | # Not working on Xenial 91 | # - os: linux 92 | # addons: 93 | # apt: 94 | # sources: 95 | # - llvm-toolchain-trusty-5.0 96 | # packages: 97 | # - libelf-dev 98 | # - clang-5.0 99 | # env: 100 | # - MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0" 101 | 102 | before_install: 103 | - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt 104 | - sudo apt-get install -y libelf-dev 105 | - $CC --version 106 | 107 | notifications: 108 | email: 109 | on_success: change 110 | on_failure: change 111 | recipients: linux-sctp@vger.kernel.org 112 | 113 | addons: 114 | coverity_scan: 115 | project: 116 | name: "sctp/lksctp-tools" 117 | description: "lksctp-tools" 118 | notification_email: linux-sctp@vger.kernel.org 119 | build_command: "./.travis/linux-covscan.sh" 120 | branch_pattern: master 121 | -------------------------------------------------------------------------------- /.travis/linux-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | VERS="master v5.4 v4.19 v4.17 v4.16 v4.13 v4.12 v4.11 v4.10" 4 | 5 | nproc=$(/usr/bin/getconf _NPROCESSORS_ONLN) 6 | basedir=$(pwd) 7 | 8 | function cleanup() 9 | { 10 | cd "$basedir" 11 | [ ! -d linux ] || rm -rf linux 12 | [ ! -d "linux-$KERNEL" ] || rm -rf "linux-$KERNEL" 13 | make distclean || : 14 | } 15 | 16 | function clone_kernel() 17 | { 18 | git clone https://github.com/torvalds/linux 19 | } 20 | 21 | function download_kernel() 22 | { 23 | VER="$1" 24 | URL="https://www.kernel.org/pub/linux/kernel/v4.x/linux-$VER.tar.xz" 25 | wget "$URL" 26 | tar xf "linux-$VER.tar.xz" 27 | } 28 | 29 | function __prep_kernel() 30 | { 31 | make mrproper 32 | make allmodconfig 33 | make -j $nproc modules_prepare 34 | make -j $nproc headers_install 35 | KERNEL_HEADERS=$(pwd)/usr/include 36 | popd 37 | } 38 | 39 | function git_prep_kernel() 40 | { 41 | VER="$1" 42 | 43 | pushd "linux" 44 | git checkout "$VER" 45 | __prep_kernel 46 | } 47 | 48 | function download_prep_kernel() 49 | { 50 | VER="$1" 51 | 52 | pushd "linux-$VER" 53 | __prep_kernel 54 | } 55 | 56 | function build_lksctp() 57 | { 58 | local use_builddir="$1" 59 | 60 | make distclean || : 61 | ./bootstrap 62 | 63 | #CFLAGS="-Werror" 64 | if [ -n "$KERNEL_HEADERS" ]; then 65 | CFLAGS="$CFLAGS -I$KERNEL_HEADERS" 66 | fi 67 | export CFLAGS 68 | 69 | if [ "$use_builddir" == 1 ]; then 70 | mkdir build 71 | pushd build 72 | ../configure 73 | else 74 | ./configure 75 | fi 76 | 77 | make -j $nproc 78 | 79 | make -j $nproc distcheck 80 | 81 | if [ "$use_builddir" == 1 ]; then 82 | popd 83 | rm -rf build 84 | fi 85 | } 86 | 87 | # When building the coverity_scan branch, allow only the 6th job to continue 88 | # to avoid travis-ci/travis-ci#1975. 6th = gcc7, linux tip 89 | if [[ "${TRAVIS_BRANCH}" == "coverity_scan" ]]; then 90 | exit 0 91 | fi 92 | 93 | trap cleanup EXIT 94 | if [ -z "$KERNEL" ]; then 95 | clone_kernel 96 | 97 | for ver in $VERS; do 98 | git_prep_kernel "$ver" 99 | build_lksctp 100 | build_lksctp 1 101 | done 102 | else 103 | if [ "$KERNEL" == 'master' ]; then 104 | clone_kernel 105 | git_prep_kernel "$KERNEL" 106 | else 107 | download_kernel "$KERNEL" 108 | download_prep_kernel "$KERNEL" 109 | fi 110 | build_lksctp 111 | build_lksctp 1 112 | fi 113 | -------------------------------------------------------------------------------- /.travis/linux-covscan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | KERNEL=master TRAVIS_BRANCH=none ./.travis/linux-build.sh 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | The initial developer and founder of the project: 2 | ------------------------------------------------- 3 | La Monte H.P. Yarroll 4 | 5 | Current Maintainer: 6 | ------------------- 7 | Vlad Yasevich 8 | Daniel Borkmann 9 | 10 | Previous Maintainers: 11 | -------------------- 12 | Sridhar Samudrala 13 | Jon Grimm 14 | 15 | Contributors: 16 | ------------- 17 | Karl Knutson 18 | Xingang Guo 19 | Daisy Chang 20 | Inaky Perez-Gonzalez 21 | Hui Huang 22 | Dajiang Zhang 23 | Ryan Layer 24 | Francois-Xavier Kowalski 25 | Frank Filz 26 | Ivan Skytte Jorgensen 27 | Neil Horman 28 | Michael Biebl 29 | Wei Yongjun 30 | Sam Miller 31 | Andrei Pelinescu-Onciul 32 | Michele Baldessari 33 | Michael Tuexen 34 | Fan Du 35 | 36 | Are you missing? drop us a line! 37 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | HOW TO COMPILE, RUN AND INSTALL 2 | ------------------------------- 3 | 4 | CONTENTS 5 | -------- 6 | 7 | The lksctp-tools package is intended for two audiences. 8 | 1) SCTP application developers 9 | 2) LKSCTP project developers 10 | 11 | For SCTP application developers, this package provides the user-level 12 | C language header files and a library for accessing SCTP specific 13 | application programming interfaces not provided by the standard sockets. 14 | 15 | For LKSCTP project developers, this package provides the functional 16 | and API regression tests. 17 | 18 | For either role, this project provides sample code, utilities, and 19 | tests that one may find useful. 20 | 21 | The below INSTALL directions are provided with in each of these roles. 22 | 23 | NOTE: To build, run and install the lksctp-tools package, your system is 24 | required to be running with linux-2.5.36, or a later version of the 25 | kernel, configured with the Network options "SCTP Configuration" 26 | support enabled. 27 | 28 | ______________________________________________________________________ 29 | 30 | 31 | INSTALLATION 32 | ------------- 33 | Prerequisite: A Linux kernel with SCTP support. This may come stock with 34 | your distrbution (some day), or you will need to build your own 2.5.36 or 35 | later kernel. 36 | 37 | To install/build the lksctp-tools utilities/tests do the following: 38 | 39 | 1) Untar the lksctp-tools directory from the gzipped tarball. This creates a 40 | subdirectory called lksctp-tools-x.y.z. 41 | 42 | Ensure you have autoconf, automake and libtool packages installed on your 43 | system. 44 | 45 | 2) Run ./bootstrap 46 | 47 | 3) Run ./configure 48 | 49 | 4) Run make 50 | 51 | 5) To run the SCTP kernel regression tests, 52 | 53 | $ cd src/func_tests 54 | $ make v4test (regression tests for the IPv4 socket support) 55 | $ make v6test (regression tests for the IPv6 socket support) 56 | 57 | 6) Run other SCTP test tools/applications in src/apps directory to verify the 58 | running SCTP. 59 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Makefile.vars 2 | include $(top_srcdir)/Makefile.rules 3 | 4 | DISTCLEANFILES += config.h stamp-h libtool 5 | MAINTAINERCLEANFILES += aclocal.m4 config.h.in configure stamp-h.in \ 6 | config.h stamp-h 7 | 8 | EXTRA_DIST += ChangeLog AUTHORS COPYING COPYING.lib INSTALL \ 9 | README ROADMAP NEWS \ 10 | Makefile.vars Makefile.rules Makefile.dirs 11 | 12 | pkgconfigdir = $(libdir)/pkgconfig 13 | pkgconfig_DATA = libsctp.pc 14 | EXTRA_DIST += libsctp.pc.in 15 | DISTCLEANFILES += libsctp.pc 16 | 17 | # bin or src products may be required to generate stuff in test/ 18 | SUBDIRS = man bin src doc 19 | 20 | ACLOCAL_AMFLAGS=-I m4 21 | 22 | # Libtool support 23 | LIBTOOL_DEPS = @LIBTOOL_DEPS@ 24 | libtool: $(LIBTOOL_DEPS) 25 | $(SHELL) ./config.status --recheck 26 | 27 | ## FIXME: Your stuff here 28 | -------------------------------------------------------------------------------- /Makefile.dirs: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | # 3 | # Define here directories you want 4 | 5 | rootbindir = /bin 6 | rootsbindir = /sbin 7 | rootlibdir = /lib 8 | 9 | localedir = $(datadir)/locale 10 | pkgsysconfdir = $(sysconfdir)/@PACKAGE@ 11 | pkgdocdir = $(datadir)/@PACKAGE@ 12 | 13 | vpkgsysconfdir = $(pkgsysconfdir)/v@VERSION@ 14 | vpkgdatadir = $(pkgdatadir)/v@VERSION@ 15 | vpkglibdir = $(pkglibdir)/v@VERSION@ 16 | vpkgdocdir = $(docdir)/v@VERSION@ 17 | 18 | # List here all the directories you want listed in the file to be used 19 | # in your programs: 20 | 21 | directories := \ 22 | localedir \ 23 | pkgsysconfdir \ 24 | rootbindir \ 25 | rootlibdir \ 26 | rootsbindir \ 27 | vpkgdatadir \ 28 | vpkgdocdir \ 29 | vpkglibdir \ 30 | vpkgsysconfdir \ 31 | \ 32 | bindir \ 33 | datadir \ 34 | libdir \ 35 | pkgdatadir \ 36 | pkgdocdir \ 37 | pkglibdir \ 38 | sbindir 39 | 40 | # To modify this target for another language, just copy, paste and 41 | # modify the target to generate directories.h. We depend on 42 | # config.status and Makefile.dirs, as anything changed is going to be 43 | # reflected there. 44 | 45 | # This is for generating the list in C/C++ 46 | directories.h: $(top_builddir)/config.status $(top_srcdir)/Makefile.dirs 47 | @rm -f $@ 48 | @echo -n "Creating $@ ..." 49 | @echo "#ifndef __$(subst .,_,$@)__" > $@ 50 | @echo "# define __$(subst .,_,$@)__" >> $@ 51 | @echo "" >> $@ 52 | @echo -e $(foreach v,$(directories),$(shell echo 'D_$(v) \"$($v)\"\\n')) \ 53 | | sed 's/^ *D_/# define D_/' >> $@ 54 | @echo "#endif" >> $@ 55 | @echo " done" 56 | 57 | DISTCLEANFILES += directories.h 58 | MAINTAINERCLEANFILES += directories.h 59 | 60 | ## FIXME: Your stuff here 61 | -------------------------------------------------------------------------------- /Makefile.rules: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | # 3 | # Generate pre-parsed C code. 4 | %.i: %.c 5 | $(COMPILE) -E -c $^ -o $@ 6 | 7 | .PRECIOUS: %.i 8 | %.ci: %.i 9 | -grep -v -e "^#" -e "^ *$$" $^ | indent > $@ 10 | mv -f $@ $^ 11 | 12 | 13 | ## FIXME: Your stuff here 14 | 15 | edit = @sed \ 16 | -e "s|\@bindir\@|$(bindir)|" \ 17 | -e "s|\@libdir\@|$(libdir)|" \ 18 | -e "s|\@PACKAGE\@|$(PACKAGE)|" \ 19 | -e "s|\@LIBWITHSCTP_CURRENT\@|$(LIBWITHSCTP_CURRENT)|" \ 20 | -e "s|\@LIBWITHSCTP_REVISION\@|$(LIBWITHSCTP_REVISION)|" \ 21 | -e "s|\@LIBWITHSCTP_AGE\@|$(LIBWITHSCTP_AGE)|" 22 | -------------------------------------------------------------------------------- /Makefile.vars: -------------------------------------------------------------------------------- 1 | # -*-makefile-*- 2 | # 3 | # type: deep, strictness: gnu 4 | 5 | MAINTAINERCLEANFILES = Makefile.in 6 | DISTCLEANFILES = \\\#*\\\# Makefile 7 | CLEANFILES = 8 | MOSTLYCLEANFILES = *~ *.[aios] *.bak *.ci *.io 9 | 10 | EXTRA_DIST = 11 | 12 | LATEX = @LATEX@ 13 | DVIPS = @DVIPS@ 14 | DVIPDFM = @DVIPDFM@ 15 | ENSCRIPTBIN = @ENSCRIPTBIN@ 16 | PS2PDF = @PS2PDF@ 17 | 18 | ## FIXME: Your stuff here 19 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 2 | The Linux Kernel SCTP Reference Implementation release 0.5.0 is included in 3 | Linux 2.5 Kernel release 2.5.34 and up. 4 | 5 | From release 0.6.0 and on, we will adopt the new build and installation 6 | process for lksctp users and developers. Please check the INSTALL and 7 | ROADMAP for more details. 8 | 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | (C) Copyright 2007 Hewlett-Packard Development Company, L.P. 2 | (C) Copyright IBM Corp. 2001, 2003 3 | Copyright 2001 Motorola, Cisco, Intel, Nokia, La Monte Yarroll. 4 | Copyright 2002 Nokia, La Monte Yarroll, Intel. 5 | 6 | This is the lksctp-tools package for Linux Kernel SCTP Reference 7 | Implementation. 8 | 9 | This package is intended to supplement the Linux Kernel SCTP 10 | Reference Implementation now available in the Linux kernel source 11 | tree in versions 2.5.36 and following. For more information on LKSCTP 12 | see the below section titled "LKSCTP - Linux Kernel SCTP." 13 | 14 | lksctp-tools 15 | ____________ 16 | 17 | The lksctp-tools package is intended for two audiences. 18 | 1) SCTP application developers 19 | 2) LKSCTP project developers 20 | 21 | For SCTP application developers, this package provides the user-level 22 | C language header files and a library for accessing SCTP specific 23 | application programming interfaces not provided by the standard sockets. 24 | 25 | For LKSCTP project developers, this package provides the API 26 | regression and functional tests. Developers should also check 27 | lksctp_tests package that provides low level kernel tests. These 28 | are available from git.kernel.org. 29 | 30 | For either role, this project provides sample code, utilities, and 31 | tests that one may find useful. 32 | 33 | 34 | LKSCTP - Linux Kernel SCTP 35 | __________________________ 36 | 37 | The Linux Kernel SCTP Reference Implementation is free software; you 38 | can redistribute it and/or modify it under the terms of the GNU 39 | General Public License as published by the Free Software Foundation; 40 | either version 2, or (at your option) any later version. For more 41 | information on licensing terms, please see the file COPYING in this 42 | directory. 43 | 44 | SCTP (Stream Control Transmission Protocol) is a message oriented, 45 | reliable transport protocol, with congestion control, support for 46 | transparent multi-homing, and multiple ordered streams of messages. 47 | RFC2960 defines the core protocol. The IETF SIGTRAN Working Group 48 | developed SCTP. The primary architects are Randy Stewart and Qiaobing 49 | Xie. 50 | 51 | The Kernel Reference is first and foremost an exposition of 52 | RFC2960 and related documents. You will find that the comments and 53 | variable names tie closely back to the RFC and Internet Drafts. 54 | 55 | This work was started by a small team of developers at Motorola. 56 | Throughout this document, "we" refers to that team. We intend for the 57 | meaning of "we" to expand to include the whole development community, 58 | all 27 million programmers on the planet. 59 | 60 | The Kernel Reference has loose origins in the SCTP User Space Reference 61 | by Randy Stewart and Qiaobing Xie. 62 | 63 | MANIFEST 64 | -------- 65 | . 66 | |-- bin 67 | |-- doc 68 | |-- man 69 | |-- src 70 | |-- apps 71 | |-- func_tests 72 | |-- include 73 | | `-- netinet 74 | |-- lib 75 | |-- testlib 76 | `-- withsctp 77 | 78 | You may want to check the following files: 79 | 80 | COPYING.lib Licensing terms of libsctp 81 | COPYING Licensing terms of other pieces of the package 82 | ROADMAP A tour around the files in the distribution of SCTP-tools. 83 | INSTALL How to install and run this beast. 84 | ChangeLog What has changed since the last release? 85 | 86 | DESIGN GOALS 87 | ------------ 88 | 89 | - A primary design goal is to reflect RFC 2960 as closely as 90 | practical. We have changed many names from the user space reference to 91 | follow the draft as closely as possible. We have also included 92 | extensive quotes from the draft adjacent to the code which implements 93 | them. 94 | 95 | - The other primary design goal is to integrate Linux kernel data 96 | structures and idioms as much as possible. The test framework (in 97 | directory test/) provides many of the functions which would otherwise 98 | come from the kernel. The test frame does use libc features, but the 99 | state machine code should be libc-free. 100 | 101 | - A lesser design goal is to completely describe the actions for each 102 | state transition in an sctp_command_t (see sctp_command.h). This 103 | means that the state functions (sctp_state_fn_t in sctp_sm.h) are NOT 104 | allowed to modify their endpoint, association, or chunk arguments. 105 | This is enforced by const modifiers--please respect the compiler 106 | warnings. All actions must be described in the last argument to the 107 | state function. 108 | 109 | - A byte order convention for dealing with the SCTP chunk headers: 110 | all SCTP chunks, regardless if the chunk is to be sent outbound 111 | to the network or was received inbound from the network, the header portion 112 | of the chunk is ALWAYS created and retained in the NETWORK BYTE ORDER. 113 | 114 | - An error code handling convention is to return negative values internally. 115 | The sk->err field holds a positive valued errno values, so will need our 116 | internal values negated. 117 | 118 | - We are moving toward an XP development model. So far we have 119 | adopted pair-programming, coding-to-test (functional and unit), design 120 | through refactoring, and story-based planning. 121 | 122 | In order to make XP work, it is very important that we have a complete 123 | set of tests for the code. We can not safely refactor major parts of 124 | the code without a way to find the things we break. If you decide to 125 | extend the SCTP Kernel Implementation we ask that you do the following: 126 | 127 | 1) Pick an XP story. Tell linux-sctp@vger.kernel.org 128 | 2) Write a functional test for that XP story. The functional 129 | test defines "DONE" for the story. 130 | 3) Submit the functional test as a Pull Request on GitHub. 131 | 4) Write unit tests for any new "objects" you define. 132 | 5) Implement your feature. 133 | 6) Submit the feature and the unit tests as a separate 134 | GitHub Pull Request. 135 | 136 | Look in src/func_tests and in lksctp-tests package for examples of of tests. 137 | Please do not submit code that fails its own tests or any of the unit tests. 138 | If it fails a functional test, please document that with the submission. 139 | 140 | Another XP requirement is to code only what is you need to make the 141 | current test work. Where this means omitting required features, we 142 | have put in prominent BUG comments describing the omitted 143 | functionality. 144 | 145 | FEATURES 146 | -------- 147 | This implementation uses a fairly compact cookie which is isolated in 148 | its own substructure of SCTP_association. We have been moving toward 149 | aggregating data elements which need to travel together to minimize 150 | copying of individual elements in favour of more efficient structure 151 | copies. 152 | 153 | You will find what we believe to be the smallest possible Internet 154 | simulator in the middle of the function test_kernel.c:simulate_internet(). 155 | The simulator makes a few simplifying assumptions... 156 | 157 | MAILING LISTS and WEB SITES 158 | --------------------------- 159 | https://github.com/sctp/lksctp-tools/ 160 | 161 | This is the lksctp project webpage. The wiki section contains 162 | more info about it, including which RFCs it supports. 163 | 164 | linux-sctp@vger.kernel.org 165 | 166 | This is the discussion list for developers. Join this list if 167 | you are interested in following the day-to-day activities of 168 | the SCTP Kernel Reference Implementation development community. 169 | See subscription directions at: 170 | http://vger.kernel.org/vger-lists.html#linux-sctp 171 | 172 | http://www.sctp.org 173 | 174 | This is Randy Stewart's SCTP web site. 175 | 176 | http://sctp.de 177 | 178 | This is Michael Tuexen's SCTP web site. Michael has collected 179 | dozens of documents related to SCTP. 180 | -------------------------------------------------------------------------------- /ROADMAP: -------------------------------------------------------------------------------- 1 | TOUR 2 | ---- 3 | COPYING.lib Licensing terms of libsctp 4 | 5 | COPYING Licensing terms of other pieces of the package 6 | 7 | README Read this before developing. 8 | 9 | ChangeLog What has changed since the last release? 10 | 11 | AUTHORS Developers name list. 12 | 13 | INSTALL How to build and install this package. 14 | 15 | doc/ All the relevant Internet Drafts and RFC's. 16 | 17 | doc/states.txt This is a detailed state table for SCTP. It makes a 18 | pretty good index for RFC2960 too... 19 | 20 | man/ SCTP man pages 21 | 22 | src/ Implementation of the user space library, include files - 23 | this should go, some day, into glibc - as well as a set 24 | of SCTP test tools and test programs. 25 | 26 | src/apps SCTP test applications. 27 | 28 | src/func_tests SCTP functional tests. 29 | 30 | src/lib Sources for SCTP library libsctp.a. 31 | 32 | src/testlib Sources for SCTP test library libsctputil.a. 33 | 34 | src/include/netinet 35 | Header files needed for user space development. 36 | 37 | bin/ Scripts for lksctp build, installation and execution. 38 | 39 | test/ Testframe functional and unit tests. These tests use a 40 | framework which enables running lksctp code in userspace. 41 | 42 | test/linux/include 43 | This include heirarchy includes special versions of 44 | kernel include files needed by the user-space test 45 | frame. 46 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | compile 2 | depcomp 3 | install-sh 4 | ltmain.sh 5 | missing 6 | -------------------------------------------------------------------------------- /bin/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | 5 | noinst_SCRIPTS = aaaa 6 | 7 | EXTRA_DIST += $(noinst_SCRIPTS) 8 | 9 | -------------------------------------------------------------------------------- /bin/aaaa: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Run all the stuff we need to generate the configure and Makefile.in 4 | # in the automake process. 5 | # 6 | # The order needs to be that. If autoheader does not run after 7 | # autoconf, it doesn't get all the symbols right. As automake requires 8 | # config.h.in, created by autoheader, it needs to run after it. 9 | # 10 | # $Id: aaaa,v 1.1.1.1 2002/08/06 22:31:05 inaky Exp $ 11 | 12 | 13 | set -ex 14 | 15 | aclocal 16 | autoconf 17 | autoheader 18 | # Set GNU strictness 19 | #automake --foreign 20 | automake --gnu 21 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # -*- sh -*- 3 | set -ex # exit on error 4 | libtoolize --force --copy 5 | aclocal 6 | autoheader 7 | automake --foreign --add-missing --copy 8 | autoconf 9 | if [ "$1" = "-a" ]; then 10 | ./configure --prefix=/usr --enable-shared --enable-static 11 | make 12 | make dist 13 | fi 14 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sctp/lksctp-tools/37d5f1225573b91d706a5e547d081f79963a9deb/configure.ac -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Makefile.vars 2 | include $(top_srcdir)/Makefile.rules 3 | 4 | internet_drafts = \ 5 | draft-stewart-tsvwg-sctpipv6-00.txt \ 6 | draft-stewart-tsvwg-sctpscore-01.txt 7 | 8 | rfcs = rfc2960.txt rfc3257.txt rfc3286.txt rfc3309.txt rfc3554.txt \ 9 | rfc3758.txt rfc3873.txt rfc4460.txt rfc4820.txt rfc4895.txt \ 10 | rfc4960.txt rfc5061.txt rfc5062.txt rfc6458.txt 11 | 12 | EXTRA_DIST += $(rfcs) $(internet_drafts) 13 | -------------------------------------------------------------------------------- /doc/draft-stewart-tsvwg-sctpipv6-00.txt: -------------------------------------------------------------------------------- 1 | Network Working Group R. R. Stewart 2 | INTERNET-DRA S. Deering 3 | Cisco 4 | 5 | expires in six months June 1,2001 6 | 7 | 8 | 9 | IPv6 addressing and Stream Control Transmission Protocol 10 | 11 | 12 | Status of This Memo 13 | 14 | This document is an Internet-Draft and is in full conformance with 15 | all provisions of Section 10 of [RFC2026]. Internet-Drafts are 16 | working documents of the Internet Engineering Task Force (IETF), its 17 | areas, and its working groups. Note that other groups may also 18 | distribute working documents as Internet-Drafts. 19 | 20 | The list of current Internet-Drafts can be accessed at 21 | http://www.ietf.org/ietf/1id-abstracts.txt 22 | 23 | The list of Internet-Draft Shadow Directories can be accessed at 24 | http://www.ietf.org/shadow.html. 25 | 26 | Abstract 27 | 28 | Stream Control Transmission Protocol [RFC2960] provides transparent 29 | multi-homing to its upper layer users. This multi-homing is 30 | accomplished through the passing of address parameters in the 31 | initial setup message used by SCTP. In an IPv4 network all addresses 32 | are passed with no consideration for their scope and routeablility. 33 | In a IPv6 network special considerations MUST be made to properly 34 | bring up associations between SCTP endpoints that have IPv6 35 | [RFC2460] addresses bound within their association. This document 36 | defines those considerations and enumerates general rules 37 | that an SCTP endpoint MUST use in formulating both the INIT and 38 | INIT-ACK chunks. 39 | 40 | 41 | Table Of Contents 42 | 43 | 44 | 45 | 46 | 1. Introduction 47 | 48 | 49 | Stream Control Transmission Protocol [RFC2960] provides transparent 50 | multi-homing to its upper layer users. This multi-homing is 51 | accomplished through the passing of address parameters in the 52 | initial setup message used by SCTP. In an IPv4 network all addresses 53 | are passed with no consideration for their scope and routeablility. 54 | In a IPv6 network special considerations MUST be made to properly 55 | bring up associations between SCTP endpoints that have IPv6 56 | [RFC2460] addresses bound within their association. This document 57 | defines those considerations and enumerates general rules 58 | that an SCTP endpoint MUST use in formulating both the INIT and 59 | INIT-ACK chunks. 60 | 61 | The emphasis in the rules laid out in this document are to prevent 62 | an SCTP endpoint from listing an IPv6 address that is outside of its 63 | routeable scope to a peer endpoint. This will prevent black-hole 64 | conditions that may cause the unexpected failure of SCTP associations. 65 | 66 | 2. Conventions 67 | 68 | The keywords MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, 69 | SHOULD NOT, RECOMMENDED, NOT RECOMMENDED, MAY, and OPTIONAL, when 70 | they appear in this document, are to be interpreted as described in 71 | [RFC2119]. 72 | 73 | 3. Special rules for IPv6 address scoping 74 | 75 | When selecting IPv6 addresses to include as parameters in the INIT 76 | chunk the following rules MUST be applied: 77 | 78 | A1) The INIT chunk SHOULD NOT include any IPv6 Link Local 79 | address parameters unless the source or destination address 80 | in the IPv6 header is a Link Local address. 81 | 82 | A2) If IPv6 Link Local address parameters are included in the 83 | INIT chunk, Link Local addresses that are NOT on the same 84 | physical Link as that of the destination or source 85 | IPv6 address (found in the IPv6 header) MUST NOT be included. 86 | 87 | A3) The INIT chunk SHOULD NOT include any IPv6 Site Local 88 | address parameters unless the source or destination address 89 | in the IPv6 header is a Site Local address. 90 | 91 | A4) If IPv6 Site Local addresses are included in the INIT chunk, 92 | Site Local address that are NOT on the same site MUST NOT 93 | be included. 94 | 95 | A5) If the destination and source address of the INIT is an 96 | IPv6 Global address then the sender SHOULD NOT include any 97 | Site Local or Link Local IPv6 address parameters in the 98 | INIT chunk. 99 | 100 | When responding to an INIT chunk and selecting IPv6 address 101 | parameters to be included in the INIT-ACK chunk, the following rules 102 | MUST be applied: 103 | 104 | B1) The INIT-ACK chunk SHOULD NOT include any IPv6 Link Local 105 | address parameters unless the source or destination address 106 | in the IPv6 header of the INIT chunk is a Link Local address. 107 | 108 | B2) If IPv6 Link Local address parameters are included in the 109 | INIT-ACK chunk, Link Local addresses that are NOT on the same 110 | physical Link as the source or destination address in the 111 | IPv6 header of the INIT chunk MUST NOT be included. 112 | 113 | B3) The INIT-ACK chunk SHOULD NOT include any IPv6 Site Local 114 | address parameters unless the source or destination address 115 | in the IPv6 header of the INIT chunk is a Site Local address. 116 | 117 | B4) If IPv6 Site Local addresses are included in the INIT-ACK 118 | chunk, Site Local address that are NOT on the same site 119 | as the received INIT chunk MUST NOT be included. 120 | 121 | B5) If the destination and source address of the INIT is an 122 | IPv6 Global address then the sender SHOULD NOT include any 123 | Site Local or Link Local IPv6 address parameters in the 124 | INIT-ACK chunk. 125 | 126 | 4. Authors addresses 127 | 128 | 129 | Randall R. Stewart 130 | 24 Burning Bush Trail. 131 | Crystal Lake, IL 60012 132 | USA 133 | Phone: +1 815 477 2127 134 | EMail: rrs@cisco.com 135 | 136 | Stephen E. Deering 137 | Cisco Systems, Inc. 138 | 170 West Tasman Drive 139 | San Jose, CA 95134-1706 140 | USA 141 | 142 | Phone: +1 408 527 8213 143 | Fax: +1 408 527 8254 144 | EMail: deering@cisco.com 145 | 146 | 147 | 5. References 148 | 149 | [RFC2026] Bradner, S., "The Internet Standards Process -- Revision 150 | 3", BCP 9, RFC 2026, October 1996. 151 | 152 | [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 153 | Requirement Levels", BCP 14, RFC 2119, March 1997. 154 | 155 | [RFC2460] S. Deering, R. Hinden, "Internet Protocol, 156 | Version 6 (IPv6) Specification." December 1998. 157 | 158 | [RFC2960] R. R. Stewart, Q. Xie, K. Morneault, C. Sharp, 159 | H. J. Schwarzbauer, T. Taylor, I. Rytina, M. Kalla, L. Zhang, 160 | and, V. Paxson, "Stream Control Transmission Protocol," RFC 161 | 2960, October 2000. 162 | -------------------------------------------------------------------------------- /doc/ols.sty: -------------------------------------------------------------------------------- 1 | 2 | % TEMPLATE for Usenix papers, specifically to meet requirements of 3 | % TCL97 committee. 4 | % originally a template for producing IEEE-format articles using LaTeX. 5 | % written by Matthew Ward, CS Department, Worcester Polytechnic Institute. 6 | % adapted by David Beazley for his excellent SWIG paper in Proceedings, 7 | % Tcl 96 8 | % turned into a smartass generic template by De Clarke, with thanks to 9 | % both the above pioneers 10 | % use at your own risk. Complaints to /dev/null. 11 | % make it two column with no page numbering, default is 10 point 12 | 13 | % adapted for Ottawa Linux Symposium 14 | 15 | % include following in document. 16 | %\documentclass[twocolumn]{article} 17 | %\usepackage{usits,epsfig} 18 | \pagestyle{empty} 19 | 20 | %set dimensions of columns, gap between columns, and space between paragraphs 21 | %\setlength{\textheight}{8.75in} 22 | \setlength{\textheight}{9.0in} 23 | \setlength{\columnsep}{0.25in} 24 | \setlength{\textwidth}{6.45in} 25 | \setlength{\footskip}{0.0in} 26 | \setlength{\topmargin}{0.0in} 27 | \setlength{\headheight}{0.0in} 28 | \setlength{\headsep}{0.0in} 29 | \setlength{\oddsidemargin}{0in} 30 | %\setlength{\oddsidemargin}{-.065in} 31 | %\setlength{\oddsidemargin}{-.17in} 32 | \setlength{\parindent}{0pc} 33 | \setlength{\parskip}{\baselineskip} 34 | 35 | % started out with art10.sty and modified params to conform to IEEE format 36 | % further mods to conform to Usenix standard 37 | 38 | \makeatletter 39 | %as Latex considers descenders in its calculation of interline spacing, 40 | %to get 12 point spacing for normalsize text, must set it to 10 points 41 | \def\@normalsize{\@setsize\normalsize{12pt}\xpt\@xpt 42 | \abovedisplayskip 10pt plus2pt minus5pt\belowdisplayskip \abovedisplayskip 43 | \abovedisplayshortskip \z@ plus3pt\belowdisplayshortskip 6pt plus3pt 44 | minus3pt\let\@listi\@listI} 45 | 46 | %need a 12 pt font size for subsection and abstract headings 47 | \def\subsize{\@setsize\subsize{12pt}\xipt\@xipt} 48 | 49 | %make section titles bold and 12 point, 2 blank lines before, 1 after 50 | \def\section{\@startsection {section}{1}{\z@}{24pt plus 2pt minus 2pt} 51 | {12pt plus 2pt minus 2pt}{\large\bf}} 52 | 53 | %make subsection titles bold and 11 point, 1 blank line before, 1 after 54 | \def\subsection{\@startsection {subsection}{2}{\z@}{12pt plus 2pt minus 2pt} 55 | {12pt plus 2pt minus 2pt}{\subsize\bf}} 56 | \makeatother 57 | -------------------------------------------------------------------------------- /doc/style_guide.txt: -------------------------------------------------------------------------------- 1 | This is the style guide for the LKSCTP Project. 2 | 3 | 4 | 1.0 Introduction 5 | 6 | Use the Linux kernel coding style as the base, 7 | linux/Documentation/CodingStyle. 8 | 9 | This is intended as the IETF kernel reference code for RFC2960 and the 10 | SCTP API. As such, readability is paramount. We attempt to follow 11 | the names from RFC2960 as closely as practical given the constrains of 12 | C and the Linux kernel naming conventions. 13 | 14 | Here are the approximate naming rules we use. Those marked 15 | [obsolescent] will go away once we purge the last vestiges of them. 16 | 17 | 1) [obsolescent] If a name appears in RFC 2960 or the API draft we try 18 | to use it as closely as permitted by C syntax without ADDING "_". 19 | This usually means names of the form "xyzAbc". E.g. "Duplicate TSN" 20 | from RFC2960 became "DuplicateTSN", but "a_rwnd" is unaltered. 21 | 22 | New names should use this revised rule 1: 23 | 24 | If a name appears in RFC 2960 or the API draft we try to use it as 25 | closely as permitted by C syntax without using upper case letters. 26 | This usually means names of the form "xyz_abc". E.g. "Duplicate 27 | TSN" from RFC2960 became "duplicate_tsn", but "a_rwnd" is 28 | unaltered. Remember the acronyms still need to be upper case in 29 | comments. 30 | 31 | 2) [obsolescent] If a name refers to a struct which appears on the wire we use 32 | the form "struct xyzAbc". This is historically because we inherited most 33 | of these from the user space implementation. E.g. "struct sctpHeader". 34 | 35 | 3) There is no rule 3. 36 | 37 | 4) All functions start with "sctp_". Uh, yeah, well, uh... 38 | 39 | 5) Constants have the form "XYZ_ABC" per K&R. 40 | 41 | 6) [obsolecent] If "XYZ" is an acronym it SHOULD be capitalized as in 42 | "XYZ_abc" or "XYZabc" unless overridden by rule 2 or rule 4. E.g. 43 | "struct SCTP_association". 44 | 45 | New names should use this revised rule 6: 46 | 47 | Names with anronyms SHOULD map them to lower case, E.g. 48 | "struct sctp_association". 49 | 50 | 7) All remaining names SHOULD use the form "xyz_abc". E.g. "int too_big". 51 | 52 | 8) Deviations from these rules are bugs and need to be fixed. 53 | 54 | 55 | 2.0 Architectural and Procedural Standards 56 | 57 | The core metaphors are the state machine (sctp_do_sm(), related 58 | functions) and the smart pipe (inqueue, outqueue, ULPqueue, packet). 59 | 60 | The state machine breaks down into a pure functional core, 61 | sctp_sm_statefuns.c, with no side effects, and an explicit set of side 62 | effects, sctp_sm_sideeffects.c. 63 | 64 | Every function, typedef, enum, and struct needs a descriptive comment. 65 | 66 | 3.0 /* Comments */ 67 | 68 | Except as noted below, make all comments full sentences. 69 | 70 | Proper behaviour is to spell-cheque your comments. Those colourful 71 | American spellings will not be rejected. 72 | 73 | Start all sentences with a capital letter. Do not begin sentences 74 | with symbols which must be all lower case. Sentences end with a 75 | period, question mark, or exclamation point. Punctuation at the end 76 | of a sentence has two trailing spaces or a trailing newline. 77 | 78 | Comments should confine themselves to expressing the INTENT of the code. 79 | 80 | If comments do not agree with the code, then we have a BUG. 81 | 82 | Passive voice should be avoided. 83 | 84 | Every function, typedef, enum, and struct needs a descriptive 85 | comment. 86 | 87 | /* All comments are C comments, */ 88 | // not C++ comments. 89 | 90 | /* Multiline comments should 91 | * look like this. 92 | */ 93 | 94 | Every #endif should include a comment describing the matching #if. 95 | E.g. 96 | 97 | #if 0 98 | #endif /* 0 */ 99 | 100 | A struct sk_buff_head needs a comment describing the REAL type of its 101 | elements. 102 | 103 | To disable a section of code use 104 | #if 0 105 | #endif /* 0 */ 106 | rather than /* */. The if/endif pair safely interoperates with 107 | existing comments. 108 | 109 | 4.0 Appearance & Pretty printing 110 | 111 | Put a space after every keyword. 112 | 113 | Here is an example function: 114 | 115 | retval_t my_fun(int foo, struct SCTP_struct *bar) 116 | { 117 | statement; 118 | } 119 | 120 | Every switch statement should have a default clause. If the default 121 | can never happen, default should crash or otherwise report failure. 122 | 123 | A loop with no body looks like this: 124 | 125 | while (test()) { 126 | /* Do nothing. */ 127 | } 128 | 129 | If a compound condition or arithemetic expression extends beyond the 130 | 79 character limit, put the operators at the end of the line. E.g. 131 | 132 | if ((NULL == map->tsn_map) || 133 | (NULL == map->overflow_map) || 134 | (map->len == 0)) { 135 | ... 136 | 137 | 138 | The if/else style must follow that of K&R style, for example: 139 | 140 | if (foo) { 141 | ... 142 | } else { 143 | ... 144 | } 145 | 146 | Unrequired whitespace should be removed from the end of lines and end of 147 | file. Hardtabs should be used where possible. 148 | 149 | 150 | 5.0 Compiler and Behavior issues 151 | 152 | When comparing a constant to a variable, put the constant on the 153 | left. The compiler will tell you if you ommited a '='. E.g. 154 | 155 | if (MY_CONSTANT == var) { 156 | whatever(); 157 | } 158 | 159 | Please eliminate all compiler warnings. "Compilation errors are, in a 160 | way, unit test failures of their own. They tell us that the 161 | implementation does not match the specification." -- check.sf.net tutorial 162 | 163 | Please make forward declarations for all functions in the appropriate 164 | header files. This helps us detect interface changes. 165 | 166 | Whenever practical, allocate a large block of memory OUTSIDE a loop 167 | and then populate it inside the loop, rather than allocating many 168 | small blocks inside the loop. 169 | 170 | Do not use #ifdef TEST_FRAME unless absolutely necessary. In 171 | particular, if you simply call kernel functions which are not defined 172 | in the test frame, please add them to the test frame. The only case 173 | we know of which is difficult to handle is static inline functions. 174 | 175 | We require using this style of initialization: 176 | 177 | struct in_ifaddr eth2_ifa = 178 | {.ifa_next = NULL, .ifa_dev = NULL, .ifa_local = 0, .ifa_address = 0}; 179 | 180 | Keyword initializations are less susceptible to bugs due to changes in 181 | the underlying structures. 182 | 183 | 184 | 6.0 Version changes 185 | 186 | The lksctp-tools packages uses the "M.m.p" versioning model for both 187 | the package itself & the provided shared libraries: 188 | 189 | - (M)-ajor revision change means both source & binary incompatibility 190 | (user source code change might be required) 191 | 192 | - (m)-inor revision change means source compatibility, while ABI might 193 | not be preserved (rebuild is required) 194 | 195 | - (p)-atchlevel change means that both API & ABI are preserved. 196 | -------------------------------------------------------------------------------- /doc/template.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 1999-2000 Cisco, Inc. 3 | * Copyright (c) 1999-2001 Motorola, Inc. 4 | * Copyright (c) 2001 International Business Machines, Corp. 5 | * Copyright (c) 2001 Intel Corp. 6 | * Copyright (c) 2001 Nokia, Inc. 7 | * Copyright (c) 2001 La Monte H.P. Yarroll 8 | * 9 | * This file is part of the SCTP kernel Implementation 10 | * 11 | * $Header: /home/CVS/tsp/SCTP/sctp-tools/doc/template.c,v 1.1.1.1 2002/08/06 22:31:05 inaky Exp $ 12 | * 13 | * These functions frob the sctp nagle structure. 14 | * 15 | * The SCTP implementation is free software; 16 | * you can redistribute it and/or modify it under the terms of 17 | * the GNU General Public License as published by 18 | * the Free Software Foundation; either version 2, or (at your option) 19 | * any later version. 20 | * 21 | * The SCTP implementation is distributed in the hope that it 22 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 23 | * ************************ 24 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | * See the GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with GNU CC; see the file COPYING. If not, write to 29 | * the Free Software Foundation, 59 Temple Place - Suite 330, 30 | * Boston, MA 02111-1307, USA. 31 | * 32 | * Please send any bug reports or fixes you make to the 33 | * email address(es): 34 | * lksctp developers 35 | * 36 | * Or submit a bug report through the following website: 37 | * https://github.com/sctp/lksctp-tools/ 38 | * 39 | * Written or modified by: 40 | * La Monte H.P. Yarroll 41 | * 42 | * Any bugs reported given to us we will try to fix... any fixes shared will 43 | * be incorporated into the next SCTP release. 44 | */ 45 | static char *cvs_id __attribute__ ((unused)) = "$Id: template.c,v 1.1.1.1 2002/08/06 22:31:05 inaky Exp $"; 46 | 47 | #include 48 | -------------------------------------------------------------------------------- /libsctp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: sctp 7 | Description: User-level SCTP API library 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lsctp 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /lksctp-tools.spec.in: -------------------------------------------------------------------------------- 1 | # -*- rpm-spec -*- 2 | # 3 | # lksctp-tools.spec.in --- RPM'ed lksctp-tools 4 | # Author : Francois-Xavier Kowalski 5 | # Created On : Sat Jan 10 14:53:53 2004 6 | # Last Modified By: Vlad Yasevich 7 | # Last Modified On: Tue Jan 08 10:56 EDT 2013 8 | # 9 | # (c) Copyright Hewlett-Packard Company 2004 10 | # (C) Copyright IBM Corp. 2004 11 | # 12 | # This program is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU General Public 14 | # License v2 as published by the Free Software Foundation; only 15 | # version 2 of the License is valid for this software, unless 16 | # explicitly otherwise stated. 17 | # 18 | # This software is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU General Public 24 | # License v2 along with this program; if not, write to the 25 | # Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 26 | # MA 02139, USA. 27 | 28 | Summary: User-space access to Linux Kernel SCTP 29 | Name: @PACKAGE@ 30 | Version: @VERSION@ 31 | Release: 1 32 | License: LGPL 33 | Group: System Environment/Libraries 34 | URL: https://github.com/sctp/lksctp-tools/ 35 | Source0: https://github.com/sctp/%{name}/archive/%{name}-%{version}.tar.gz 36 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot 37 | BuildRequires: gcc 38 | #BuildRequires: tetex, tetex-latex, tetex-xdvi, tetex-dvips 39 | #BuildRequires: ghostscript, enscript 40 | BuildRequires: libtool, automake, autoconf 41 | 42 | %description 43 | This is the lksctp-tools package for Linux Kernel SCTP Reference 44 | Implementation. 45 | 46 | This package is intended to supplement the Linux Kernel SCTP Reference 47 | Implementation now available in the Linux kernel source tree in 48 | versions 2.5.36 and following. For more information on LKSCTP see the 49 | package documentation README file, section titled "LKSCTP - Linux 50 | Kernel SCTP." 51 | 52 | This package contains the base run-time library & command-line tools. 53 | 54 | %package devel 55 | Summary: Development kit for lksctp-tools 56 | Group: Development/Libraries 57 | Requires: %{name} = %{version} 58 | Requires: glibc-devel 59 | 60 | %description devel 61 | Development kit for lksctp-tools 62 | 63 | - Man pages 64 | - Header files 65 | - Static libraries 66 | - Symlinks to dynamic libraries 67 | - Tutorial source code 68 | 69 | %package doc 70 | Summary: Documents pertaining to SCTP 71 | Group: System Environment/Libraries 72 | Requires: %{name} = %{version} 73 | 74 | %description doc 75 | Documents pertaining to LKSCTP & SCTP in general 76 | - IETF RFC's & Internet Drafts 77 | 78 | %prep 79 | %setup -q -n %{name}-%{version} 80 | 81 | %build 82 | %configure --enable-shared --enable-static 83 | make 84 | 85 | %install 86 | rm -rf $RPM_BUILD_ROOT 87 | make install DESTDIR="$RPM_BUILD_ROOT" 88 | 89 | %clean 90 | rm -rf $RPM_BUILD_ROOT 91 | 92 | %post 93 | /sbin/ldconfig 94 | 95 | %postun 96 | /sbin/ldconfig 97 | 98 | %files 99 | %defattr(-,root,root,-) 100 | %doc AUTHORS COPYING ChangeLog COPYING.lib 101 | %{_bindir}/* 102 | %{_libdir}/libsctp.so.* 103 | %{_libdir}/@PACKAGE@/* 104 | 105 | %files devel 106 | %defattr(-,root,root,-) 107 | %{_includedir} 108 | %{_libdir}/libsctp.so 109 | %{_libdir}/libsctp.a 110 | %{_libdir}/libsctp.la 111 | %{_datadir}/@PACKAGE@/* 112 | %{_mandir}/* 113 | 114 | %files doc 115 | %defattr(-,root,root,-) 116 | %doc doc/*.txt 117 | 118 | %changelog 119 | * Mon May 09 2016 Marcelo Ricardo Leitner 1.0.17-1 120 | - 1.0.17 Release 121 | 122 | * Tue Feb 18 2014 Daniel Borkmann 1.0.16-1 123 | - 1.0.16 Release 124 | 125 | * Sun May 12 2013 Daniel Borkmann 1.0.15-1 126 | - 1.0.15 Release 127 | 128 | * Wed Apr 05 2013 Daniel Borkmann 1.0.14-1 129 | - 1.0.14 Release 130 | 131 | * Wed Jan 23 2013 Daniel Borkmann 1.0.13-1 132 | - 1.0.13 Release 133 | 134 | * Tue Jan 08 2013 Vlad Yasevich 1.0.12-1 135 | - 1.0.12 Release 136 | 137 | * Wed Oct 21 2009 Vlad Yasevich 1.0.11-1 138 | - 1.0.11 Release 139 | 140 | * Fri Mar 27 2009 Vlad Yasevich 1.0.10-1 141 | - 1.0.10 Release 142 | 143 | * Sun Jun 13 2008 Vlad Yasevich 1.0.9-1 144 | - 1.0.9 Release 145 | 146 | * Fri Feb 01 2008 Vlad Yasevich 1.0.8-1 147 | - 1.0.8 Release 148 | 149 | * Fri Jun 29 2007 Vlad Yasevich 1.0.7-1 150 | - 1.0.7 Release 151 | 152 | * Fri Feb 3 2006 Sridhar Samudrala 1.0.6-1 153 | - 1.0.6 Release 154 | 155 | * Tue Jan 3 2006 Sridhar Samudrala 1.0.5-1 156 | - 1.0.5 Release 157 | 158 | * Fri Oct 28 2005 Sridhar Samudrala 1.0.4-1 159 | - 1.0.4 Release 160 | 161 | * Thu Sep 1 2005 Sridhar Samudrala 1.0.3-1 162 | - 1.0.3 Release 163 | 164 | * Thu Dec 30 2004 Sridhar Samudrala 1.0.2-1 165 | - 1.0.2 Release 166 | 167 | * Tue May 11 2004 Sridhar Samudrala 1.0.1-1 168 | - 1.0.1 Release 169 | 170 | * Thu Feb 26 2004 Sridhar Samudrala 1.0.0-1 171 | - 1.0.0 Release 172 | 173 | * Fri Feb 6 2004 Francois-Xavier Kowalski 0.9.0-1 174 | - package only .txt doc files 175 | 176 | * Wed Feb 4 2004 Francois-Xavier Kowalski 0.7.5-1 177 | - badly placed & undelivered files 178 | - simplified delivery list 179 | 180 | * Tue Jan 27 2004 Francois-Xavier Kowalski 0.7.5-1 181 | - Integrate comment from project team 182 | 183 | * Sat Jan 10 2004 Francois-Xavier Kowalski 2.6.0_test7_0.7.4-1 184 | - Creation 185 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | *.m4 2 | !sctp.m4 3 | -------------------------------------------------------------------------------- /m4/sctp.m4: -------------------------------------------------------------------------------- 1 | # Handy references: 2 | # https://www.gnu.org/software/autoconf/manual/autoconf.html#Generic-Structures 3 | # AC_CHECK_MEMBER (aggregate.member, [action-if-found], [action-if-not-found], [includes = 'AC_INCLUDES_DEFAULT']) 4 | # https://www.gnu.org/software/autoconf/manual/autoconf.html#Generic-Types 5 | # AC_CHECK_TYPE (type, [action-if-found], [action-if-not-found], [includes = 'AC_INCLUDES_DEFAULT']) 6 | 7 | # Macros to assist on probing kernel features 8 | # Probes if a type is defined 9 | AC_DEFUN([LKSCTP_CHECK_TYPE], [ 10 | AC_CHECK_TYPE([$1], 11 | AC_DEFINE([$2], 1, 12 | [Define if $1 is present.]) 13 | AM_CONDITIONAL([$2], [true]), 14 | AM_CONDITIONAL([$2], [false]), 15 | [AC_INCLUDES_DEFAULT 16 | #ifdef HAVE_STDINT_H 17 | # include 18 | #endif 19 | #ifdef HAVE_SYS_SOCKET_H 20 | # include 21 | #endif 22 | #ifdef HAVE_LINUX_SCTP_H 23 | # include 24 | #endif 25 | ])]) 26 | 27 | # Probes if a struct has a given member 28 | AC_DEFUN([LKSCTP_CHECK_MEMBER], [ 29 | AC_CHECK_MEMBER([$1], 30 | AC_DEFINE([$2], 1, 31 | [Define if $1 is present.]) 32 | AM_CONDITIONAL([$2], [true]), 33 | AM_CONDITIONAL([$2], [false]), 34 | [AC_INCLUDES_DEFAULT 35 | #ifdef HAVE_STDINT_H 36 | # include 37 | #endif 38 | #ifdef HAVE_SYS_SOCKET_H 39 | # include 40 | #endif 41 | #ifdef HAVE_LINUX_SCTP_H 42 | # include 43 | #endif 44 | ])]) 45 | 46 | # Probes if a declaration is present 47 | AC_DEFUN([LKSCTP_CHECK_DECL], [ 48 | AC_CHECK_DECL([$1], 49 | AC_DEFINE([$2], 1, 50 | [Define if $1 is present.]) 51 | AM_CONDITIONAL([$2], [true]), 52 | AM_CONDITIONAL([$2], [false]), 53 | [AC_INCLUDES_DEFAULT 54 | #ifdef HAVE_STDINT_H 55 | # include 56 | #endif 57 | #ifdef HAVE_SYS_SOCKET_H 58 | # include 59 | #endif 60 | #ifdef HAVE_LINUX_SCTP_H 61 | # include 62 | #endif 63 | ])]) 64 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | include $(top_srcdir)/Makefile.vars 4 | include $(top_srcdir)/Makefile.rules 5 | 6 | man7_MANS = sctp.7 7 | 8 | man3_MANS = sctp_bindx.3 sctp_getladdrs.3 sctp_getpaddrs.3 sctp_opt_info.3 \ 9 | sctp_peeloff.3 sctp_recvmsg.3 sctp_sendmsg.3 sctp_connectx.3 \ 10 | sctp_send.3 sctp_sendv.3 sctp_recvv.3 11 | 12 | EXTRA_DIST += $(man3_MANS) $(man7_MANS) 13 | -------------------------------------------------------------------------------- /man/sctp_bindx.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_BINDX 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_bindx \- Add or remove bind addresses on a socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_bindx(int " sd ", struct sockaddr * " addrs ", int " addrcnt , 18 | .BI " int " flags ); 19 | .fi 20 | .SH DESCRIPTION 21 | .BR sctp_bindx 22 | adds or removes a set of bind addresses passed in the array 23 | .I addrs 24 | to/from the socket 25 | .I sd. 26 | .I addrcnt 27 | is the number of addresses in the array and the 28 | .I flags 29 | paramater indicates if the addresses need to be added or removed. 30 | .PP 31 | If 32 | .I sd 33 | is an IPv4 socket, the addresses passed must be IPv4 addresses. If 34 | .I sd 35 | is an IPv6 socket, the addresses passed can be either IPv4 or IPv6 36 | addresses. 37 | .PP 38 | .I addrs 39 | is a pointer to an array of one or more socket addresses. Each address is 40 | contained in its appropriate structure(i.e. struct sockaddr_in or struct 41 | sockaddr_in6). The family of the address type must be used to distinguish 42 | the address length. The caller specifies the number of addresses in the 43 | array with 44 | .I addrcnt. 45 | .PP 46 | The 47 | .I flags 48 | parameter can be either 49 | .B SCTP_BINDX_ADD_ADDR 50 | or 51 | .B SCTP_BINDX_REM_ADDR. 52 | An application can use 53 | .B SCTP_BINDX_ADD_ADDR 54 | to associate additional addresses with an endpoint after calling 55 | .BR bind(2). 56 | .B SCTP_BINDX_REM_ADDR 57 | directs SCTP to remove the given addresses from the association. 58 | A caller may not remove all addresses from an association. It will 59 | fail with 60 | .B EINVAL. 61 | .SH "RETURN VALUE" 62 | On success, 0 is returned. On failure, \-1 is returned, and 63 | .I errno 64 | is set appropriately. 65 | .SH ERRORS 66 | .TP 67 | .B EBADF 68 | .I sd 69 | is not a valid descriptor. 70 | .TP 71 | .B ENOTSOCK 72 | .I sd 73 | is a descriptor for a file, not a socket. 74 | .TP 75 | .B EFAULT 76 | Error while copying in or out from the user address space. 77 | .TP 78 | .B EINVAL 79 | Invalid port or address or trying to remove all addresses from an association. 80 | .TP 81 | .B EACCES 82 | The address is protected, and the user is not the super-user. 83 | .SH "SEE ALSO" 84 | .BR sctp (7) 85 | .BR sctp_sendmsg (3), 86 | .BR sctp_sendv (3), 87 | .BR sctp_send (3), 88 | .BR sctp_recvmsg (3), 89 | .BR sctp_recvv (3), 90 | .BR sctp_peeloff (3), 91 | .BR sctp_getpaddrs (3), 92 | .BR sctp_getladdrs (3), 93 | .BR sctp_opt_info (3), 94 | .BR sctp_connectx (3) 95 | -------------------------------------------------------------------------------- /man/sctp_connectx.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Frank Filz IBM Corp. 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_CONNECTX 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_connectx \- initiate a connection on an SCTP socket using multiple 11 | destination addresses. 12 | .SH SYNOPSIS 13 | .nf 14 | .B #include 15 | .B #include 16 | .B #include 17 | .sp 18 | .BI "int sctp_connectx(int " sd ", struct sockaddr * " addrs ", int " addrcnt, 19 | .BI " sctp_assoc_t * "id ); 20 | .fi 21 | .SH DESCRIPTION 22 | .BR sctp_connectx 23 | initiates a connection to a set of addresses passed in the array 24 | .I addrs 25 | to/from the socket 26 | .I sd. 27 | .I addrcnt 28 | is the number of addresses in the array. 29 | .PP 30 | If 31 | .I sd 32 | is an IPv4 socket, the addresses passed must be IPv4 addresses. If 33 | .I sd 34 | is an IPv6 socket, the addresses passed can be either IPv4 or IPv6 35 | addresses. 36 | .PP 37 | .I addrs 38 | is a pointer to an array of one or more socket addresses. Each address is 39 | contained in its appropriate structure(i.e. struct sockaddr_in or struct 40 | sockaddr_in6). The family of the address type must be used to distinguish 41 | the address length. The caller specifies the number of addresses in the 42 | array with 43 | .I addrcnt. 44 | .PP 45 | .I id 46 | is a pointer to the association id and, if provided, will be set to the 47 | identifier of the newly created association. 48 | .SH "RETURN VALUE" 49 | On success, 0 is returned. On failure, \-1 is returned, and 50 | .I errno 51 | is set appropriately. 52 | .SH ERRORS 53 | .TP 54 | .B EBADF 55 | .I sd 56 | is not a valid descriptor. 57 | .TP 58 | .B ENOTSOCK 59 | .I sd 60 | is a descriptor for a file, not a socket. 61 | .TP 62 | .B EFAULT 63 | Error while copying in or out from the user address space. 64 | .TP 65 | .B EINVAL 66 | Invalid port or address. 67 | .TP 68 | .B EACCES 69 | The address is protected, and the user is not the super-user. 70 | .TP 71 | .B EISCONN 72 | The socket is already connected. 73 | .TP 74 | .B ECONNREFUSED 75 | No one listening on the remote address. 76 | .TP 77 | .B ETIMEDOUT 78 | Timeout while attempting connection. The server may be too 79 | busy to accept new connections. Note that for IP sockets the timeout may 80 | be very long when syncookies are enabled on the server. 81 | .TP 82 | .B ENETUNREACH 83 | Network is unreachable. 84 | .TP 85 | .B EADDRINUSE 86 | Local address is already in use. 87 | .TP 88 | .B EINPROGRESS 89 | The socket is non-blocking and the connection cannot be completed 90 | immediately. It is possible to 91 | .BR select (2) 92 | or 93 | .BR poll (2) 94 | for completion by selecting the socket for writing. After 95 | .B select 96 | indicates writability, use 97 | .BR getsockopt (2) 98 | to read the 99 | .B SO_ERROR 100 | option at level 101 | .B SOL_SOCKET 102 | to determine whether 103 | .B connect 104 | completed successfully 105 | .RB ( SO_ERROR 106 | is zero) or unsuccessfully 107 | .RB ( SO_ERROR 108 | is one of the usual error codes listed here, 109 | explaining the reason for the failure). 110 | .TP 111 | .B EALREADY 112 | The socket is non-blocking and a previous connection attempt has not yet 113 | been completed. 114 | .TP 115 | .B EAGAIN 116 | No more free local ports or insufficient entries in the routing cache. For 117 | .B PF_INET 118 | see the 119 | .B net.ipv4.ip_local_port_range 120 | sysctl in 121 | .BR ip (7) 122 | on how to increase the number of local ports. 123 | .TP 124 | .B EAFNOSUPPORT 125 | The passed address didn't have the correct address family in its 126 | .I sa_family 127 | field. 128 | .TP 129 | .B EACCES, EPERM 130 | The user tried to connect to a broadcast address without having the socket 131 | broadcast flag enabled or the connection request failed because of a local 132 | firewall rule. 133 | .SH "SEE ALSO" 134 | .BR sctp (7) 135 | .BR sctp_bindx (3), 136 | .BR sctp_sendmsg (3), 137 | .BR sctp_sendv (3), 138 | .BR sctp_send (3), 139 | .BR sctp_recvmsg (3), 140 | .BR sctp_recvv (3), 141 | .BR sctp_peeloff (3), 142 | .BR sctp_getpaddrs (3), 143 | .BR sctp_getladdrs (3), 144 | .BR sctp_opt_info (3), 145 | -------------------------------------------------------------------------------- /man/sctp_getladdrs.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_GETLADDRS 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_getladdrs \- Returns all locally bound addresses on a socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_getladdrs(int " sd ", sctp_assoc_t " assoc_id , 18 | .BI " struct sockaddr **" addrs ); 19 | .sp 20 | .BI "void sctp_freeladdrs(struct sockaddr *" addrs ); 21 | .fi 22 | .SH DESCRIPTION 23 | .BR sctp_getladdrs 24 | returns all locally bound addresses on a socket. On return, 25 | .I addrs 26 | will point to a dynamically allocated packed array of 27 | .B sockaddr 28 | structures of the appropriate type for each local address. The caller 29 | should use 30 | .BR sctp_freeladdrs 31 | to free the memory. Note that the in/out parameter 32 | .I addrs 33 | must not be NULL. 34 | .PP 35 | If 36 | .I sd 37 | is an IPv4 socket, the addresses returned will be all IPv4 addresses. If 38 | .I sd 39 | is an IPv6 socket, the addresses returned can be a mix of IPv4 or IPv6 40 | addresses. 41 | .PP 42 | For one-to-many style sockets, 43 | .I id 44 | specifies the association to query. For one-to-one style sockets, 45 | .I id 46 | is ignored. 47 | .PP 48 | If the 49 | .I id 50 | field is set to 0, then the locally bound addresses are returned 51 | without regard to any particular association. 52 | .PP 53 | .BR sctp_freeladdrs 54 | frees all the resources allocated by 55 | .BR sctp_getladdrs 56 | .SH "RETURN VALUE" 57 | On success, 58 | .BR sctp_getladdrs 59 | returns the number of local addresses bound to the socket. If the socket 60 | is unbound, 0 is returned and the value of 61 | .I *addrs 62 | is undefined. On error, 63 | .BR sctp_getladdrs 64 | returns -1 and the value of 65 | .I *addrs 66 | is undefined. 67 | .SH "SEE ALSO" 68 | .BR sctp (7) 69 | .BR sctp_bindx (3), 70 | .BR sctp_connectx (3), 71 | .BR sctp_sendmsg (3), 72 | .BR sctp_sendv (3), 73 | .BR sctp_send (3), 74 | .BR sctp_recvmsg (3), 75 | .BR sctp_recvv (3), 76 | .BR sctp_peeloff (3), 77 | .BR sctp_getpaddrs (3), 78 | .BR sctp_opt_info (3), 79 | -------------------------------------------------------------------------------- /man/sctp_getpaddrs.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_GETPADDRS 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_getpaddrs \- Returns all peer addresses in an association. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_getpaddrs(int " sd ", sctp_assoc_t " assoc_id , 18 | .BI " struct sockaddr **" addrs ); 19 | .sp 20 | .BI "void sctp_freepaddrs(struct sockaddr *" addrs ); 21 | .fi 22 | .SH DESCRIPTION 23 | .BR sctp_getpaddrs 24 | returns all peer addresses in an association. On return, 25 | .I addrs 26 | will point to a dynamically allocated packed array of 27 | .B sockaddr 28 | structures of the appropriate type for each address. The caller should use 29 | .BR sctp_freepaddrs 30 | to free the memory. Note that the in/out parameter 31 | .I addrs 32 | must not be NULL. 33 | .PP 34 | If 35 | .I sd 36 | is an IPv4 socket, the addresses returned will be all IPv4 addresses. If 37 | .I sd 38 | is an IPv6 socket, the addresses returned can be a mix of IPv4 or IPv6 39 | addresses. 40 | .PP 41 | For one-to-many style sockets, 42 | .I id 43 | specifies the association to query. For one-to-one style sockets, 44 | .I id 45 | is ignored. 46 | .PP 47 | .BR sctp_freepaddrs 48 | frees all the resources allocated by 49 | .BR sctp_getpaddrs. 50 | .SH "RETURN VALUE" 51 | On success, 52 | .BR sctp_getpaddrs 53 | returns the number of peer addresses in the association. If there is no 54 | association on this socket, 0 is returned and the value of 55 | .I *addrs 56 | is undefined. On error, 57 | .BR sctp_getpaddrs 58 | returns -1 and the value of 59 | .I *addrs 60 | is undefined. 61 | .SH "SEE ALSO" 62 | .BR sctp (7) 63 | .BR sctp_bindx (3), 64 | .BR sctp_connectx (3), 65 | .BR sctp_sendmsg (3), 66 | .BR sctp_sendv (3), 67 | .BR sctp_send (3), 68 | .BR sctp_recvmsg (3), 69 | .BR sctp_recvv (3), 70 | .BR sctp_peeloff (3), 71 | .BR sctp_getladdrs (3), 72 | .BR sctp_opt_info (3), 73 | -------------------------------------------------------------------------------- /man/sctp_opt_info.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_OPT_INFO 3 2004-01-30 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_optinfo \- Get options on a SCTP socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_opt_info(int " sd ", sctp_assoc_t " id ", int " opt , 18 | .BI " void * " arg ", socklen_t * " size); 19 | .fi 20 | .SH DESCRIPTION 21 | .BR sctp_opt_info 22 | is a wrapper library function that can be used to get SCTP level options on 23 | a socket. 24 | .I sd 25 | is the socket descriptor for which the option is requested. For one-to-many 26 | style sockets, 27 | .I id 28 | specifies the association to query. For one-to-one style sockets, 29 | .I id 30 | is ignored. 31 | .I opt 32 | specifes the SCTP socket option to get. 33 | .I arg 34 | is an option-specific structure buffer provided by the caller. 35 | .I size 36 | is a value-result parameter, initially containing the size of the buffer 37 | pointed to by 38 | .I arg 39 | and modifed on return to indicate the actual size of the value returned. 40 | .SH "RETURN VALUE" 41 | On success, 42 | .BR sctp_opt_info 43 | returns 0 and on failure -1 is returned with errno set to the appropriate 44 | error code. 45 | .SH "SEE ALSO" 46 | .BR sctp (7) 47 | .BR sctp_bindx (3), 48 | .BR sctp_connectx (3), 49 | .BR sctp_sendmsg (3), 50 | .BR sctp_sendv (3), 51 | .BR sctp_send (3), 52 | .BR sctp_recvmsg (3), 53 | .BR sctp_recvv (3), 54 | .BR sctp_peeloff (3), 55 | .BR sctp_getpaddrs (3), 56 | .BR sctp_getladdrs (3), 57 | -------------------------------------------------------------------------------- /man/sctp_peeloff.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_PEELOFF 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_peeloff \- Branch off an association into a separate socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_peeloff(int " sd ", sctp_assoc_t " assoc_id ); 18 | .BI "int sctp_peeloff_flags(int " sd ", sctp_assoc_t " assoc_id ", unsigned " flags ); 19 | .fi 20 | .SH DESCRIPTION 21 | .B sctp_peeloff 22 | branches off an existing association 23 | .I assoc_id 24 | on a one-to-many style socket 25 | .I sd 26 | into a separate socket. The new socket is a one-to-one style socket. 27 | .PP 28 | This is particularly desirable when, for instance, the application wishes to 29 | have a number of sporadic message senders/receivers remain under the original 30 | one-to-many style socket, but branch off those assocations carrying high volume 31 | data traffic into their own separate socket descriptors. 32 | 33 | .B sctp_peeloff_flags 34 | is a variant of sctp_peeloff, in which flags describing the behavior of 35 | the newly peeled off socket can be specified. Currently the supported flags 36 | are: 37 | .TP 38 | .B SOCK_NONBLOCK 39 | Specifies that the new socket should not block on io operations. 40 | .TP 41 | .B SOCK_CLOEXEC 42 | Specifies that the new socket should be closed when the owning process calls 43 | exec. 44 | .SH "RETURN VALUE" 45 | On success, the new socket descriptor representing the branched-off asociation is returned. 46 | On error, \-1 is returned, and 47 | .I errno 48 | is set appropriately. 49 | .SH ERRORS 50 | .TP 51 | .B EBADF 52 | .I sd 53 | is not a valid descriptor. 54 | .TP 55 | .B EINVAL 56 | The assoc id passed is invalid or if the socket is a one-to-one style socket. 57 | .TP 58 | .B ENOTSOCK 59 | Argument is a descriptor for a file, not a socket. 60 | .SH NOTES 61 | .TP 62 | sctp_peeloff_flags is a linux specific variant of sctp_peeloff. While it will compile on other systems, its use will result in an error return. Portable code should use sctp_peeloff. 63 | .SH "SEE ALSO" 64 | .BR sctp (7) 65 | .BR sctp_bindx (3), 66 | .BR sctp_connectx (3), 67 | .BR sctp_sendmsg (3), 68 | .BR sctp_sendv (3), 69 | .BR sctp_send (3), 70 | .BR sctp_recvmsg (3), 71 | .BR sctp_recvv (3), 72 | .BR sctp_getpaddrs (3), 73 | .BR sctp_getladdrs (3), 74 | .BR sctp_opt_info (3), 75 | -------------------------------------------------------------------------------- /man/sctp_recvmsg.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_RECVMSG 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_recvmsg \- Receive a message from a SCTP socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_recvmsg(int " sd ", void * " msg ", size_t " len , 18 | .BI " struct sockaddr * " from ", socklen_t * " fromlen , 19 | .BI " struct sctp_sndrcvinfo * " sinfo ", int * " msg_flags); 20 | .fi 21 | .SH DESCRIPTION 22 | .BR sctp_recvmsg 23 | is a wrapper library function that can be used to receive a message from 24 | a socket while using the advanced features of SCTP. 25 | .I sd 26 | is the socket descriptor on which the message pointed to by 27 | .I msg 28 | of length 29 | .I len 30 | is received. 31 | .PP 32 | If 33 | .I from 34 | is not NULL, the source address of the message is filled in. The argument 35 | .I fromlen 36 | is a value-result parameter. initialized to the size of the buffer associated 37 | with 38 | .I from , 39 | and modified on return to indicate the actual size of the address stored. 40 | .PP 41 | .I sinfo 42 | is a pointer to a sctp_sndrcvinfo structure to be filled upon receipt of the 43 | message. 44 | .I msg_flags 45 | is a pointer to a integer that is filled with any message flags like 46 | .B MSG_NOTIFICATION or 47 | .B MSG_EOR. 48 | The value of 49 | .I msg_flags 50 | pointer should be initialized to 0 to avoid unexpected behavior; 51 | .I msg_flags 52 | is also used as an input 53 | .I flags 54 | argument to 55 | .I recvmsg 56 | function. 57 | .SH "RETURN VALUE" 58 | On success, 59 | .BR sctp_recvmsg 60 | returns the number of bytes received or -1 if an error occurred. 61 | .SH "SEE ALSO" 62 | .BR sctp (7) 63 | .BR sctp_bindx (3), 64 | .BR sctp_connectx (3), 65 | .BR sctp_sendmsg (3), 66 | .BR sctp_sendv (3), 67 | .BR sctp_send (3), 68 | .BR sctp_peeloff (3), 69 | .BR sctp_getpaddrs (3), 70 | .BR sctp_getladdrs (3), 71 | .BR sctp_opt_info (3) 72 | -------------------------------------------------------------------------------- /man/sctp_recvv.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Xin Long REDHAT Corp. 2018. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_RECVV 3 2018-04-29 "Linux 4.16 "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_recvv \- Receive a message from a SCTP socket with an extensible way. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_recvv(int " sd ", const struct iovec * " iov ", int " iovlen , 18 | .BI " struct sockaddr * " from ", socklen_t * " fromlen ", void * " info , 19 | .BI " socklen_t * " infolen ", unsigned int * " infotype ", int * " flags ); 20 | .fi 21 | .SH DESCRIPTION 22 | .BR sctp_recvv 23 | provides an extensible way for the SCTP stack to pass up different SCTP 24 | attributes associated with a received message to an application. 25 | There are two types of attributes that can be returned by this call: the 26 | attribute of the received message and the attribute of the next message 27 | in the receive buffer. The caller enables the SCTP_RECVRCVINFO and 28 | SCTP_RECVNXTINFO socket options, respectively, to receive these attributes. 29 | Attributes of the received message are returned in struct sctp_rcvinfo, 30 | and attributes of the next message are returned in struct sctp_nxtinfo. 31 | If both options are enabled, both attributes are returned using the 32 | following structure. 33 | 34 | struct sctp_recvv_rn { 35 | struct sctp_rcvinfo recvv_rcvinfo; 36 | struct sctp_nxtinfo recvv_nxtinfo; 37 | }; 38 | 39 | .I sd 40 | is the socket descriptor. 41 | .I iov 42 | is the scatter buffer, and only one user message is returned in this buffer. 43 | .I iovlen 44 | is the number of elements in iov. 45 | .I from 46 | is a pointer to a buffer to be filled with the sender of the received message's 47 | address. 48 | .I fromlen 49 | is an in/out parameter describing the from length. 50 | .I info 51 | is a pointer to the buffer to hold the attributes of the received message, the 52 | structure type of info is determined by the info_type parameter. 53 | .I infolen 54 | is an in/out parameter describing the size of the info buffer. 55 | On return, 56 | .I infotype 57 | is set to the type of the info buffer, and the current defined 58 | values are as follows: 59 | .TP 60 | .B SCTP_RECVV_NOINFO 61 | If neither SCTP_RECVRCVINFO nor SCTP_RECVNXTINFO options are enabled, no 62 | attribute will be returned. If only the SCTP_RECVNXTINFO option is enabled 63 | but there is no next message in the buffer, no attribute will be returned. 64 | In these cases, *info_type will be set to SCTP_RECVV_NOINFO. 65 | .TP 66 | .B SCTP_RECVV_RCVINFO 67 | The type of info is struct sctp_rcvinfo, and the attribute relates to the 68 | received message. 69 | .TP 70 | .B SCTP_RECVV_NXTINFO 71 | The type of info is struct sctp_nxtinfo, and the attribute relates to the 72 | next message in the receive buffer. This is the case when only the 73 | SCTP_RECVNXTINFO option is enabled and there is a next message in the buffer. 74 | .TP 75 | .B SCTP_RECVV_RN 76 | The type of info is struct sctp_recvv_rn. The recvv_rcvinfo field is the 77 | attribute of the received message, and the recvv_nxtinfo field is the attribute 78 | of the next message in the buffer. This is the case when both SCTP_RECVRCVINFO 79 | and SCTP_RECVNXTINFO options are enabled and there is a next message in the 80 | receive buffer. 81 | .PP 82 | .I flags 83 | is pointer to an integer to be filled with any message flags (e.g., 84 | MSG_NOTIFICATION). 85 | .SH "RETURN VALUE" 86 | On success, 87 | .BR sctp_recvv 88 | returns the number of bytes received or -1 if an error occurred. 89 | .SH "SEE ALSO" 90 | .BR sctp (7) 91 | .BR sctp_bindx (3), 92 | .BR sctp_connectx (3), 93 | .BR sctp_sendmsg (3), 94 | .BR sctp_sendv (3), 95 | .BR sctp_send (3), 96 | .BR sctp_peeloff (3), 97 | .BR sctp_getpaddrs (3), 98 | .BR sctp_getladdrs (3), 99 | .BR sctp_opt_info (3) 100 | -------------------------------------------------------------------------------- /man/sctp_send.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_SEND 3 2005-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_send \- Send a message from a SCTP socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_send(int " sd ", const void * " msg ", size_t " len , 18 | .BI " const struct sctp_sndrcvinfo *" sinfo ", 19 | .BI " uint32_t " flags ); 20 | .fi 21 | .SH DESCRIPTION 22 | .BR sctp_send 23 | is a wrapper library function that can be used to send a message from a socket 24 | without the use of the CMSG header structures. 25 | .I sd 26 | is the socket descriptor from which the message pointed to by 27 | .I msg 28 | of length 29 | .I len 30 | is sent. 31 | .I sinfo 32 | is a pointer to a sctp_sndrcvinfo structure. 33 | .I flags 34 | parameter is composed of a bitwise OR of the flags that can be be passed as 35 | the 3rd argument of a standard sendmsg() call. 36 | .SH "RETURN VALUE" 37 | On success, 38 | .BR sctp_sendmsg 39 | returns the number of bytes sent or -1 if an error occurred. 40 | .SH "SEE ALSO" 41 | .BR sctp (7) 42 | .BR sctp_bindx (3), 43 | .BR sctp_recvmsg (3), 44 | .BR sctp_recvv (3), 45 | .BR sctp_peeloff (3), 46 | .BR sctp_getpaddrs (3), 47 | .BR sctp_getladdrs (3), 48 | .BR sctp_opt_info (3), 49 | .BR sctp_sendmsg (3), 50 | .BR sctp_sendv (3) 51 | -------------------------------------------------------------------------------- /man/sctp_sendmsg.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Sridhar Samudrala IBM Corp. 2004, 2005. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_SENDMSG 3 2004-10-25 "Linux 2.6" "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_sendmsg \- Send a message from a SCTP socket. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_sendmsg(int " sd ", const void * " msg ", size_t " len , 18 | .BI " struct sockaddr *" to ", socklen_t " tolen , 19 | .BI " uint32_t " ppid ", uint32_t " flags , 20 | .BI " uint16_t " stream_no ", uint32_t " timetolive , 21 | .BI " uint32_t " context ); 22 | .fi 23 | .SH DESCRIPTION 24 | .BR sctp_sendmsg 25 | is a wrapper library function that can be used to send a message from a socket 26 | while using the advanced features of SCTP. 27 | .I sd 28 | is the socket descriptor from which the message pointed to by 29 | .I msg 30 | of length 31 | .I len 32 | is sent. 33 | .I to 34 | is the destination address of the message and 35 | .I tolen 36 | is the length of the destination address. 37 | .I stream_no 38 | identifies the stream number that the application wishes to send this message to. 39 | .I flags 40 | parameter is composed of a bitwise OR of the following values. 41 | .TP 42 | .B SCTP_UNORDERED 43 | This flags requests the un-ordered delivery of the message. 44 | .TP 45 | .B SCTP_ADDR_OVER 46 | This flag, in the one-to-many style, requests the SCTP stack to override the 47 | primary destination address with address specified in 48 | .I to. 49 | .TP 50 | .B SCTP_ABORT 51 | Setting this flag causes the specified association to abort by sending an ABORT 52 | message to the peer(one-to-many style only). The ABORT chunk will contain an 53 | error cause 'User Initiated Abort' with cause code 12. The cause specific 54 | information of this error cause is provided in 55 | .I msg. 56 | .TP 57 | .B SCTP_EOF 58 | Setting this flag invokes the SCTP graceful shutdown procedure on the specific 59 | association(one-to-many style only). 60 | .TP 61 | .B SCTP_SENDALL 62 | This flag, if set, will cause a one-to-many style socket to send the message 63 | to all associations that are currently established on this socket. For the 64 | one-to-one style socket, this flag has no effect. 65 | .TP 66 | .B SCTP_SACK_IMMEDIATELY 67 | This flag allows the application to set the I bit of the last DATA chunk when 68 | sending each user message to make sure the corresponding SACK can be sent by 69 | peer without delay. 70 | .TP 71 | .B SCTP_PR_SCTP_{TTL|RTX|PRIO} 72 | One of these 3 pr_policies can be used through this flag with its pr_value 73 | set in timetolive parameter for this message. Note that 74 | .B sctp_sendv(3) 75 | with infotype SCTP_SENDV_PRINFO also works for PR-SCTP. 76 | .PP 77 | .I timetolive 78 | specifies the time duration in milliseconds. The sending side will expire the 79 | message if the message has not been sent to the peer within this time period. 80 | A value of 0 indicates that no timeout should occur on this message. It also 81 | works as the pr_value if flags parameter is set to pr_policy. 82 | .I ppid 83 | is an opaque unsigned value that is passed to the remote end along with the 84 | message. 85 | .I context 86 | is a 32 bit opaque value that is passed back to the upper layer along with the 87 | undelivered message if an error occurs on the send of the message. 88 | .SH "RETURN VALUE" 89 | On success, 90 | .BR sctp_sendmsg 91 | returns the number of bytes sent or -1 if an error occurred. 92 | .SH "SEE ALSO" 93 | .BR sctp (7) 94 | .BR sctp_bindx (3), 95 | .BR sctp_connectx (3), 96 | .BR sctp_sendv (3), 97 | .BR sctp_send (3), 98 | .BR sctp_recvmsg (3), 99 | .BR sctp_recvv (3), 100 | .BR sctp_peeloff (3), 101 | .BR sctp_getpaddrs (3), 102 | .BR sctp_getladdrs (3), 103 | .BR sctp_opt_info (3), 104 | -------------------------------------------------------------------------------- /man/sctp_sendv.3: -------------------------------------------------------------------------------- 1 | .\" (C) Copyright Xin Long REDHAT Corp. 2018. 2 | .\" 3 | .\" Permission is granted to distribute possibly modified copies 4 | .\" of this manual provided the header is included verbatim, 5 | .\" and in case of nontrivial modification author and date 6 | .\" of the modification is added to the header. 7 | .\" 8 | .TH SCTP_SENDV 3 2018-04-29 "Linux 4.16 "Linux Programmer's Manual" 9 | .SH NAME 10 | sctp_sendv \- Send messages from a SCTP socket with an extensible way. 11 | .SH SYNOPSIS 12 | .nf 13 | .B #include 14 | .B #include 15 | .B #include 16 | .sp 17 | .BI "int sctp_sendv(int " sd ", const struct iovec * " iov ", int " iovcnt , 18 | .BI " struct sockaddr *" addrs ", int " addrcnt ", void * " info , 19 | .BI " socklen_t " infolen ", unsigned int " infotype ", int " flags ); 20 | .fi 21 | .SH DESCRIPTION 22 | .BR sctp_sendv 23 | provides an extensible way for an application to communicate different send 24 | attributes to the SCTP stack when sending a message. There are three types 25 | of attributes that can be used to describe a message to be sent. They are 26 | struct sctp_sndinfo, struct sctp_prinfo, and struct sctp_authinfo. The 27 | following structure, sctp_sendv_spa, is defined to be used when more than 28 | one of the above attributes are needed to describe a message to be sent. 29 | 30 | struct sctp_sendv_spa { 31 | uint32_t sendv_flags; 32 | struct sctp_sndinfo sendv_sndinfo; 33 | struct sctp_prinfo sendv_prinfo; 34 | struct sctp_authinfo sendv_authinfo; 35 | }; 36 | 37 | The sendv_flags field holds a bitwise OR of SCTP_SEND_SNDINFO_VALID, 38 | SCTP_SEND_PRINFO_VALID, and SCTP_SEND_AUTHINFO_VALID indicating if 39 | the sendv_sndinfo/sendv_prinfo/sendv_authinfo fields contain valid 40 | information. 41 | 42 | .I sd 43 | is the socket descriptor. 44 | .I iov 45 | is the gather buffer, the data in the buffer is treated as a single 46 | user message. 47 | .I iovcnt 48 | is the number of elements in iov. 49 | .I addrs 50 | is an array of addresses to be used to set up an association or 51 | a single address to be used to send the message, and NULL is passed 52 | in if the caller neither wants to set up an association nor wants 53 | to send the message to a specific address. 54 | .I addrcnt 55 | is the number of addresses in the addrs array. 56 | .I info 57 | is a pointer to the buffer containing the attribute associated with the 58 | message to be sent, and the type is indicated by the info_type parameter. 59 | .I infolen 60 | is the length of info, in bytes. 61 | .I infotype 62 | identifies the type of the information provided in info ,and the current 63 | defined values are as follows: 64 | .TP 65 | .B SCTP_SENDV_NOINFO 66 | No information is provided. The parameter info is a NULL pointer, and 67 | infolen is 0. 68 | .TP 69 | .B SCTP_SENDV_SNDINFO 70 | The parameter info is pointing to a struct sctp_sndinfo. 71 | .TP 72 | .B SCTP_SENDV_PRINFO 73 | The parameter info is pointing to a struct sctp_prinfo. 74 | .TP 75 | .B SCTP_SENDV_AUTHINFO 76 | The parameter info is pointing to a struct sctp_authinfo. 77 | .TP 78 | .B SCTP_SENDV_SPA 79 | The parameter info is pointing to a struct sctp_sendv_spa. 80 | .PP 81 | .I flags 82 | The same flags as used by the sendmsg() call flags (e.g., MSG_DONTROUTE). 83 | .SH "RETURN VALUE" 84 | On success, 85 | .BR sctp_sendv 86 | returns the number of bytes sent or -1 if an error occurred. 87 | .SH "SEE ALSO" 88 | .BR sctp (7) 89 | .BR sctp_bindx (3), 90 | .BR sctp_connectx (3), 91 | .BR sctp_send (3), 92 | .BR sctp_recvmsg (3), 93 | .BR sctp_recvv (3), 94 | .BR sctp_peeloff (3), 95 | .BR sctp_getpaddrs (3), 96 | .BR sctp_getladdrs (3), 97 | .BR sctp_opt_info (3), 98 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Makefile.vars 2 | include $(top_srcdir)/Makefile.rules 3 | 4 | SUBDIRS = apps include lib testlib withsctp 5 | 6 | if BUILD_TESTS 7 | SUBDIRS += func_tests 8 | endif 9 | -------------------------------------------------------------------------------- /src/apps/.gitignore: -------------------------------------------------------------------------------- 1 | bindx_test 2 | myftp 3 | nagle_rcv 4 | nagle_snd 5 | peel_client 6 | peel_server 7 | sctp_darn 8 | sctp_status 9 | sctp_test 10 | sctp_xconnect 11 | -------------------------------------------------------------------------------- /src/apps/Makefile.am: -------------------------------------------------------------------------------- 1 | # Include these two in all the Makefile.am's!!! 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | include $(top_srcdir)/Makefile.dirs 5 | 6 | # General compilation flags 7 | AM_CPPFLAGS = -I. -I$(top_builddir)/src/include -I$(top_srcdir)/src/testlib \ 8 | -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes \ 9 | -Wimplicit-function-declaration 10 | 11 | AM_LDFLAGS = 12 | 13 | LDADD = $(top_builddir)/src/testlib/libsctputil.la \ 14 | $(top_builddir)/src/lib/libsctp.la 15 | 16 | # programs to be installed with the distriubution 17 | bin_PROGRAMS = sctp_darn sctp_test sctp_status 18 | 19 | # Test programs and libraries to build 20 | noinst_PROGRAMS = bindx_test nagle_snd nagle_rcv myftp sctp_xconnect \ 21 | peel_server peel_client sctp_test sctp_status 22 | 23 | $(top_builddir)/src/lib/libsctp.la: 24 | $(MAKE) -C $(top_builddir)/src/lib libsctp.la 25 | 26 | $(top_builddir)/src/testlib/libsctputil.la: 27 | $(MAKE) -C $(top_builddir)/src/testlib libsctputil.la 28 | 29 | # Specifying the sources 30 | bindx_test_SOURCES = bindx_test.c 31 | sctp_darn_SOURCES = sctp_darn.c sctp_darn.h 32 | sctp_test_SOURCES = sctp_test.c 33 | sctp_status_SOURCES = sctp_status.c 34 | nagle_rcv_SOURCES = nagle_rcv.c 35 | nagle_snd_SOURCES = nagle_snd.c 36 | myftp_SOURCES = myftp.c 37 | sctp_xconnect_SOURCES = sctp_xconnect.c 38 | peel_server_SOURCES = peel_server.c 39 | peel_client_SOURCES = peel_client.c 40 | 41 | # Tutorials 42 | pkgdoc_DATA = sctp_darn.c sctp_darn.h sctp_test.c sctp_status.c 43 | -------------------------------------------------------------------------------- /src/apps/bindx_test.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sctp/lksctp-tools/37d5f1225573b91d706a5e547d081f79963a9deb/src/apps/bindx_test.c -------------------------------------------------------------------------------- /src/apps/nagle_rcv.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * (C) Copyright IBM Corp. 2002, 2003 3 | * Copyright (c) 1999-2000 Cisco, Inc. 4 | * Copyright (c) 1999-2001 Motorola, Inc. 5 | * Copyright (c) 2001 Intel Corp. 6 | * Copyright (c) 2001 Nokia, Inc. 7 | * 8 | * The SCTP implementation is free software; 9 | * you can redistribute it and/or modify it under the terms of 10 | * the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * The SCTP implementation is distributed in the hope that it 15 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 16 | * ************************ 17 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with GNU CC; see the file COPYING. If not, write to 22 | * the Free Software Foundation, 59 Temple Place - Suite 330, 23 | * Boston, MA 02111-1307, USA. 24 | * 25 | * Please send any bug reports or fixes you make to the 26 | * email address(es): 27 | * lksctp developers 28 | * 29 | * Or submit a bug report through the following website: 30 | * https://github.com/sctp/lksctp-tools/ 31 | * 32 | * Any bugs reported to us we will try to fix... any fixes shared will 33 | * be incorporated into the next SCTP release. 34 | * 35 | * Written or modified by: 36 | * Ardelle Fan 37 | * Sridhar Samudrala 38 | */ 39 | 40 | /* This is a receiver for the performance test to verify Nagle's algorithm. 41 | * It creates a socket, binds to a address specified as a parameter and 42 | * goes into a receive loop waiting for 1,000,000 packets. Then it calculates 43 | * the packet receive rate, i.e. packets/second. 44 | */ 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | char *TCID = __FILE__; 62 | int TST_TOTAL = 1; 63 | int TST_CNT = 0; 64 | 65 | void 66 | usage(char *progname) 67 | { 68 | fprintf(stderr, "Usage: %s -H hostname [-P port]\n", progname); 69 | fprintf(stderr, " -H, --local\t\t local hostname,\n"); 70 | fprintf(stderr, " -P, --local-port\t local port,\n"); 71 | } 72 | 73 | int 74 | main(int argc, char *argv[]) 75 | { 76 | int sk, i; 77 | struct addrinfo *hst_res; 78 | sockaddr_storage_t host; 79 | sockaddr_storage_t msgname; 80 | struct iovec iov; 81 | struct msghdr inmessage; 82 | char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; 83 | int error, pf_class; 84 | char *big_buffer; 85 | char *local_host = NULL; 86 | int local_port = SCTP_TESTPORT_1; 87 | char port_buffer[10]; 88 | int option_index = 0; 89 | time_t from, to; 90 | int bytes_received = 0; 91 | int c; 92 | static struct option long_options[] = { 93 | {"local", 1, 0, 1}, 94 | {"local-port", 1, 0, 2}, 95 | {0, 0, 0, 0} 96 | }; 97 | 98 | /* Rather than fflush() throughout the code, set stdout to 99 | * be unbuffered. 100 | */ 101 | setvbuf(stdout, NULL, _IONBF, 0); 102 | 103 | /* Parse the arguments. */ 104 | while (1) { 105 | c = getopt_long (argc, argv, "H:P:", 106 | long_options, &option_index); 107 | if (c == -1) 108 | break; 109 | 110 | switch (c) { 111 | case 0: 112 | printf("option %s", long_options[option_index].name); 113 | if (optarg) { 114 | printf(" with arg %s", optarg); 115 | } 116 | printf("\n"); 117 | break; 118 | case 1: /* local host */ 119 | case 'H': 120 | local_host = optarg; 121 | break; 122 | case 2: /* local port */ 123 | case 'P': 124 | local_port = atoi(optarg); 125 | break; 126 | case '?': 127 | usage(argv[0]); 128 | exit(0); 129 | 130 | default: 131 | printf ("%s: unrecognized option 0%c\n", argv[0], c); 132 | usage(argv[0]); 133 | exit(1); 134 | } 135 | } 136 | 137 | if (optind < argc) 138 | { 139 | fprintf(stderr, "%s: non-option arguments are illegal: ", 140 | argv[0]); 141 | while (optind < argc) 142 | fprintf(stderr, "%s ", argv[optind++]); 143 | fprintf (stderr, "\n"); 144 | usage(argv[0]); 145 | exit(1); 146 | } 147 | 148 | if (!local_host) { 149 | fprintf(stderr, "%s: : option -H, --local is required\n", 150 | argv[0]); 151 | usage(argv[0]); 152 | exit(1); 153 | } 154 | 155 | /* Set some basic values which depend on the address family. */ 156 | if (!strcmp(local_host, "0")) 157 | local_host = "0.0.0.0"; 158 | 159 | snprintf(port_buffer, 10, "%d", local_port); 160 | error = getaddrinfo(local_host, port_buffer, NULL, &hst_res); 161 | if (error) { 162 | fprintf(stderr, "%s: getaddrinfo failed: %s\n", argv[0], local_host); 163 | exit(1); 164 | } 165 | 166 | pf_class = hst_res->ai_family; 167 | switch (pf_class) { 168 | case AF_INET: 169 | case AF_INET6: 170 | memcpy(&host.sa, hst_res->ai_addr, hst_res->ai_addrlen); 171 | break; 172 | default: 173 | fprintf(stderr, "Invalid address type.\n"); 174 | exit(1); 175 | break; 176 | } 177 | 178 | freeaddrinfo(hst_res); 179 | 180 | /* Create the endpoint which will talk to nagle_snd. */ 181 | sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP); 182 | 183 | /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */ 184 | test_enable_assoc_change(sk); 185 | 186 | /* Bind the sockets to the test port. */ 187 | test_bind(sk, &host.sa, sizeof(host)); 188 | 189 | /* Mark sk as being able to accept new associations. */ 190 | test_listen(sk, 1); 191 | 192 | printf("Listening on port:%d\n", local_port); 193 | 194 | /* Initialize inmessage for receives. */ 195 | memset(&inmessage, 0, sizeof(inmessage)); 196 | big_buffer = test_malloc(REALLY_BIG); 197 | iov.iov_base = big_buffer; 198 | iov.iov_len = REALLY_BIG; 199 | inmessage.msg_iov = &iov; 200 | inmessage.msg_iovlen = 1; 201 | inmessage.msg_control = incmsg; 202 | inmessage.msg_controllen = sizeof(incmsg); 203 | inmessage.msg_name = &msgname; 204 | inmessage.msg_namelen = sizeof(msgname); 205 | memset(&msgname, 0, sizeof(msgname)); 206 | 207 | /* Get the communication up message on sk. */ 208 | error = test_recvmsg(sk, &inmessage, MSG_WAITALL); 209 | test_check_msg_notification(&inmessage, error, 210 | sizeof(struct sctp_assoc_change), 211 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); 212 | 213 | printf("Established connection with "); 214 | if (AF_INET == msgname.sa.sa_family) 215 | printf("%d.%d.%d.%d(%d)\n", NIPQUAD(msgname.v4.sin_addr), 216 | ntohs(msgname.v4.sin_port)); 217 | if (AF_INET6 == msgname.sa.sa_family) 218 | printf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x(%d)\n", 219 | NIP6(msgname.v6.sin6_addr), ntohs(msgname.v6.sin6_port)); 220 | 221 | time(&from); 222 | for (i=0; i<1000000; i++) { 223 | inmessage.msg_controllen = sizeof(incmsg); 224 | inmessage.msg_namelen = sizeof(msgname); 225 | error = test_recvmsg(sk, &inmessage, MSG_WAITALL); 226 | if (inmessage.msg_flags & MSG_NOTIFICATION) 227 | break; 228 | printf("Received %d bytes of data\n", error); 229 | bytes_received += error; 230 | } 231 | time(&to); 232 | 233 | printf("\t%d messages(%d bytes) successfully received in %ld " 234 | "seconds.\n", i, bytes_received, to - from); 235 | printf("The receive rate is %ld bytes/second\n", 236 | bytes_received/(to - from)); 237 | 238 | /* Shut down the link. */ 239 | error = 0; 240 | close(sk); 241 | 242 | return 0; 243 | } 244 | -------------------------------------------------------------------------------- /src/apps/sctp_darn.h: -------------------------------------------------------------------------------- 1 | #ifndef __sctp_darn_h__ 2 | #define __sctp_darn_h__ 3 | 4 | #define REALLY_BIG 65536 5 | #define SCTP_TESTPORT_1 1 6 | #define SCTP_TESTPORT_2 2 7 | 8 | void parse_arguments(int argc, char *argv[]); 9 | void usage(char *argv0); 10 | int command_listen(char *arg0, int sk); 11 | int command_send(char *arg0, int *skp); 12 | int command_poll(char *arg0); 13 | int test_print_message(int sk, struct msghdr *, size_t msg_len); 14 | 15 | typedef enum { 16 | COMMAND_NONE = 0, 17 | COMMAND_LISTEN, 18 | COMMAND_SEND, 19 | COMMAND_POLL, 20 | } command_t; 21 | 22 | typedef union { 23 | struct sockaddr_storage ss; 24 | struct sockaddr_in v4; 25 | struct sockaddr_in6 v6; 26 | struct sockaddr sa; 27 | } sockaddr_storage_t; 28 | 29 | #endif /* __sctp_darn_h__ */ 30 | -------------------------------------------------------------------------------- /src/func_tests/.gitignore: -------------------------------------------------------------------------------- 1 | test_1_to_1_accept_close 2 | test_1_to_1_addrs 3 | test_1_to_1_connect 4 | test_1_to_1_connectx 5 | test_1_to_1_events 6 | test_1_to_1_initmsg_connect 7 | test_1_to_1_nonblock 8 | test_1_to_1_recvfrom 9 | test_1_to_1_recvmsg 10 | test_1_to_1_rtoinfo 11 | test_1_to_1_send 12 | test_1_to_1_sendmsg 13 | test_1_to_1_sendto 14 | test_1_to_1_shutdown 15 | test_1_to_1_socket_bind_listen 16 | test_1_to_1_sockopt 17 | test_1_to_1_threads 18 | test_assoc_abort 19 | test_assoc_shutdown 20 | test_autoclose 21 | test_basic 22 | test_basic_v6 23 | test_connect 24 | test_connectx 25 | test_fragments 26 | test_fragments_v6 27 | test_getname 28 | test_getname_v6 29 | test_inaddr_any 30 | test_inaddr_any_v6 31 | test_interleave 32 | test_interleave_v6 33 | test_peeloff 34 | test_peeloff_v6 35 | test_re_conf 36 | test_re_conf_v6 37 | test_recvmsg 38 | test_sctp_sendrecvmsg 39 | test_sctp_sendrecvmsg_v6 40 | test_sockopt 41 | test_sockopt_v6 42 | test_tcp_style 43 | test_tcp_style_v6 44 | test_timetolive 45 | test_timetolive_v6 46 | -------------------------------------------------------------------------------- /src/func_tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Include these two in all the Makefile.am's!!! 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | include $(top_srcdir)/Makefile.dirs 5 | 6 | # General compilation flags 7 | AM_CPPFLAGS = -I. -I$(top_builddir)/src/include -I$(top_srcdir)/src/testlib \ 8 | -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes \ 9 | -Wimplicit-function-declaration 10 | 11 | AM_LDFLAGS = -lpthread 12 | 13 | LDADD = $(top_builddir)/src/testlib/libsctputil.la \ 14 | $(top_builddir)/src/lib/libsctp.la 15 | 16 | V6FLAGS = -DCONFIG_IPV6=1 -DTEST_V6=1 ${DEFS} ${INCLUDES} ${CFLAGS} 17 | 18 | # Test programs and libraries to build 19 | PASSING_KERN_TESTS = \ 20 | test_assoc_abort \ 21 | test_assoc_shutdown \ 22 | test_autoclose \ 23 | test_basic \ 24 | test_fragments \ 25 | test_inaddr_any \ 26 | test_peeloff \ 27 | test_sockopt \ 28 | test_connect \ 29 | test_connectx \ 30 | test_recvmsg \ 31 | test_timetolive \ 32 | test_sctp_sendrecvmsg \ 33 | test_getname \ 34 | test_tcp_style\ 35 | test_1_to_1_socket_bind_listen \ 36 | test_1_to_1_accept_close \ 37 | test_1_to_1_connect \ 38 | test_1_to_1_connectx \ 39 | test_1_to_1_send \ 40 | test_1_to_1_sendto \ 41 | test_1_to_1_sendmsg \ 42 | test_1_to_1_recvfrom \ 43 | test_1_to_1_recvmsg \ 44 | test_1_to_1_shutdown \ 45 | test_1_to_1_sockopt \ 46 | test_1_to_1_addrs \ 47 | test_1_to_1_nonblock \ 48 | test_1_to_1_rtoinfo \ 49 | test_1_to_1_events \ 50 | test_1_to_1_threads \ 51 | test_1_to_1_initmsg_connect 52 | 53 | PASSING_V6_KERN_TESTS = \ 54 | test_basic_v6 \ 55 | test_sockopt_v6 \ 56 | test_fragments_v6 \ 57 | test_inaddr_any_v6 \ 58 | test_peeloff_v6 \ 59 | test_timetolive_v6 \ 60 | test_sctp_sendrecvmsg_v6 \ 61 | test_getname_v6 \ 62 | test_tcp_style_v6 63 | 64 | if HAVE_SCTP_SENDV 65 | PASSING_KERN_TESTS += \ 66 | test_sctp_sendvrecvv 67 | PASSING_V6_KERN_TESTS += \ 68 | test_sctp_sendvrecvv_v6 69 | endif 70 | 71 | if HAVE_SCTP_FRAGMENT_INTERLEAVE 72 | PASSING_KERN_TESTS += \ 73 | test_interleave 74 | PASSING_V6_KERN_TESTS += \ 75 | test_interleave_v6 76 | endif 77 | 78 | if HAVE_SCTP_STREAM_RECONFIG 79 | PASSING_KERN_TESTS += \ 80 | test_re_conf 81 | PASSING_V6_KERN_TESTS += \ 82 | test_re_conf_v6 83 | endif 84 | 85 | noinst_PROGRAMS = ${PASSING_KERN_TESTS} ${PASSING_V6_KERN_TESTS} 86 | 87 | $(top_builddir)/src/lib/libsctp.la: 88 | $(MAKE) -C $(top_builddir)/src/lib libsctp.la 89 | 90 | $(top_builddir)/src/testlib/libsctputil.la: 91 | $(MAKE) -C $(top_builddir)/src/testlib libsctputil.la 92 | 93 | # These are tests for live kernels which pass. 94 | v4test: ${PASSING_KERN_TESTS} 95 | @for a in $^; \ 96 | do \ 97 | echo "./$$a"; \ 98 | if ./$$a; \ 99 | then \ 100 | echo "$$a passes"; \ 101 | echo ""; \ 102 | else \ 103 | echo "$$a fails"; \ 104 | exit 1; \ 105 | fi; \ 106 | sleep 1; \ 107 | done 108 | @echo "Hoody hoo!" 109 | 110 | # These are tests for live kernels which pass. 111 | v6test: ${PASSING_V6_KERN_TESTS} 112 | @for a in $^; \ 113 | do \ 114 | echo "./$$a"; \ 115 | if ./$$a; \ 116 | then \ 117 | echo "$$a passes"; \ 118 | echo ""; \ 119 | else \ 120 | echo "$$a fails"; \ 121 | exit 1; \ 122 | fi; \ 123 | sleep 1; \ 124 | done 125 | @echo "Hoody hoo!" 126 | 127 | # Specifying the sources 128 | test_assoc_abort_SOURCES = test_assoc_abort.c 129 | test_assoc_shutdown_SOURCES = test_assoc_shutdown.c 130 | test_autoclose_SOURCES = test_autoclose.c 131 | test_basic_SOURCES = test_basic.c 132 | test_fragments_SOURCES = test_fragments.c 133 | test_inaddr_any_SOURCES = test_inaddr_any.c 134 | test_peeloff_SOURCES = test_peeloff.c 135 | test_sockopt_SOURCES = test_sockopt.c 136 | test_connect_SOURCES = test_connect.c 137 | test_connectx_SOURCES = test_connectx.c 138 | test_recvmsg_SOURCES = test_recvmsg.c 139 | test_timetolive_SOURCES = test_timetolive.c 140 | test_sctp_sendrecvmsg_SOURCES = test_sctp_sendrecvmsg.c 141 | test_sctp_sendvrecvv_SOURCES = test_sctp_sendvrecvv.c 142 | test_getname_SOURCES = test_getname.c 143 | test_tcp_style_SOURCES = test_tcp_style.c 144 | 145 | test_1_to_1_socket_bind_listen_SOURCES = test_1_to_1_socket_bind_listen.c 146 | test_1_to_1_accept_close_SOURCES = test_1_to_1_accept_close.c 147 | test_1_to_1_connect_SOURCES = test_1_to_1_connect.c 148 | test_1_to_1_connectx_SOURCES = test_1_to_1_connectx.c 149 | test_1_to_1_send_SOURCES = test_1_to_1_send.c 150 | test_1_to_1_sendto_SOURCES = test_1_to_1_sendto.c 151 | test_1_to_1_sendmsg_SOURCES = test_1_to_1_sendmsg.c 152 | test_1_to_1_recvfrom_SOURCES = test_1_to_1_recvfrom.c 153 | test_1_to_1_recvmsg_SOURCES = test_1_to_1_recvmsg.c 154 | test_1_to_1_shutdown_SOURCES = test_1_to_1_shutdown.c 155 | test_1_to_1_sockopt_SOURCES = test_1_to_1_sockopt.c 156 | test_1_to_1_addrs_SOURCES = test_1_to_1_addrs.c 157 | test_1_to_1_nonblock_SOURCES = test_1_to_1_nonblock.c 158 | test_1_to_1_rtoinfo_SOURCES = test_1_to_1_rtoinfo.c 159 | test_1_to_1_events_SOURCES = test_1_to_1_events.c 160 | test_1_to_1_threads_SOURCES = test_1_to_1_threads.c 161 | test_1_to_1_initmsg_connect_SOURCES = test_1_to_1_initmsg_connect.c 162 | 163 | # 164 | # Specifying objects rules for "v6test" 165 | # 166 | test_basic_v6_SOURCES = test_basic.c 167 | test_basic_v6_CFLAGS = ${V6FLAGS} 168 | 169 | test_sockopt_v6_SOURCES = test_sockopt.c 170 | test_sockopt_v6_CFLAGS = ${V6FLAGS} 171 | 172 | test_fragments_v6_SOURCES = test_fragments.c 173 | test_fragments_v6_CFLAGS = ${V6FLAGS} 174 | 175 | test_inaddr_any_v6_SOURCES = test_inaddr_any.c 176 | test_inaddr_any_v6_CFLAGS = ${V6FLAGS} 177 | 178 | test_peeloff_v6_SOURCES = test_peeloff.c 179 | test_peeloff_v6_CFLAGS = ${V6FLAGS} 180 | 181 | test_timetolive_v6_SOURCES = test_timetolive.c 182 | test_timetolive_v6_CFLAGS = ${V6FLAGS} 183 | 184 | test_sctp_sendrecvmsg_v6_SOURCES = test_sctp_sendrecvmsg.c 185 | test_sctp_sendvrecvv_v6_SOURCES = test_sctp_sendvrecvv.c 186 | test_sctp_sendrecvmsg_v6_CFLAGS = ${V6FLAGS} 187 | test_sctp_sendvrecvv_v6_CFLAGS = ${V6FLAGS} 188 | 189 | test_getname_v6_SOURCES = test_getname.c 190 | test_getname_v6_CFLAGS = ${V6FLAGS} 191 | 192 | test_tcp_style_v6_SOURCES = test_tcp_style.c 193 | test_tcp_style_v6_CFLAGS = ${V6FLAGS} 194 | 195 | test_interleave_v6_SOURCES = test_interleave.c 196 | test_interleave_v6_CFLAGS = ${V6FLAGS} 197 | 198 | test_re_conf_v6_SOURCES = test_re_conf.c 199 | test_re_conf_v6_CFLAGS = ${V6FLAGS} 200 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_events.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This test tests the events for 1-1 style sockets. 6 | * 7 | * The SCTP implementation is free software; 8 | * you can redistribute it and/or modify it under the terms of 9 | * the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * The SCTP implementation is distributed in the hope that it 14 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 15 | * ************************ 16 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with GNU CC; see the file COPYING. If not, write to 21 | * the Free Software Foundation, 59 Temple Place - Suite 330, 22 | * Boston, MA 02111-1307, USA. 23 | * 24 | * Please send any bug reports or fixes you make to the 25 | * email address(es): 26 | * lksctp developers 27 | * 28 | * Or submit a bug report through the following website: 29 | * https://github.com/sctp/lksctp-tools/ 30 | * 31 | * 32 | * Any bugs reported given to us we will try to fix... any fixes shared will 33 | * be incorporated into the next SCTP release. 34 | * 35 | */ 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include /* needed by linux/sctp.h */ 41 | #include 42 | #include /* for sockaddr_in */ 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | char *TCID = __FILE__; 49 | int TST_TOTAL = 4; 50 | int TST_CNT = 0; 51 | 52 | int 53 | main(int argc, char *argv[]) 54 | { 55 | int svr_sk, clt_sk,acpt_sk; 56 | struct sockaddr_in svr_loop, clt_loop,acpt_loop; 57 | struct iovec iov, out_iov; 58 | struct msghdr inmessage, outmessage; 59 | char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; 60 | char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; 61 | int error; 62 | socklen_t len; 63 | char *big_buffer; 64 | struct sctp_event_subscribe event; 65 | struct cmsghdr *cmsg; 66 | struct sctp_sndrcvinfo *sinfo; 67 | char *message = "hello, world!\n"; 68 | uint32_t ppid; 69 | uint32_t stream; 70 | 71 | /* Rather than fflush() throughout the code, set stdout to 72 | * be unbuffered. 73 | */ 74 | setvbuf(stdout, NULL, _IONBF, 0); 75 | 76 | /* Initialize the server and client addresses. */ 77 | svr_loop.sin_family = AF_INET; 78 | svr_loop.sin_addr.s_addr = SCTP_IP_LOOPBACK; 79 | svr_loop.sin_port = htons(SCTP_TESTPORT_1); 80 | 81 | clt_loop.sin_family = AF_INET; 82 | clt_loop.sin_addr.s_addr = SCTP_IP_LOOPBACK; 83 | clt_loop.sin_port = htons(SCTP_TESTPORT_1); 84 | 85 | /* Create and bind the server socket. */ 86 | svr_sk = test_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); 87 | test_bind(svr_sk, (struct sockaddr *) &svr_loop, sizeof(svr_loop)); 88 | 89 | /* Mark server socket as being able to accept new associations. */ 90 | test_listen(svr_sk, 3); 91 | 92 | /* Create the client socket. */ 93 | clt_sk = test_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); 94 | 95 | memset(&event, 0, sizeof(event)); 96 | event.sctp_data_io_event = 1; 97 | event.sctp_association_event = 1; 98 | event.sctp_shutdown_event = 1; 99 | #ifdef HAVE_SCTP_AUTH_NO_AUTH 100 | event.sctp_authentication_event = 1; 101 | #endif 102 | len = sizeof(struct sctp_event_subscribe); 103 | test_setsockopt(svr_sk, SCTP_EVENTS, &event, len); 104 | test_setsockopt(clt_sk, SCTP_EVENTS, &event, len); 105 | 106 | len = sizeof(struct sockaddr_in); 107 | test_connect(clt_sk, (struct sockaddr *) &clt_loop, len); 108 | 109 | acpt_sk = test_accept(svr_sk, (struct sockaddr *) &acpt_loop, &len); 110 | 111 | /* Build up a msghdr structure we can use for all sending. */ 112 | memset(&outmessage, 0, sizeof(outmessage)); 113 | outmessage.msg_name = &svr_loop; 114 | outmessage.msg_namelen = sizeof(svr_loop); 115 | outmessage.msg_iov = &out_iov; 116 | outmessage.msg_iovlen = 1; 117 | outmessage.msg_control = outcmsg; 118 | outmessage.msg_controllen = sizeof(outcmsg); 119 | outmessage.msg_flags = 0; 120 | 121 | cmsg = CMSG_FIRSTHDR(&outmessage); 122 | cmsg->cmsg_level = IPPROTO_SCTP; 123 | cmsg->cmsg_type = SCTP_SNDRCV; 124 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 125 | outmessage.msg_controllen = cmsg->cmsg_len; 126 | sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); 127 | memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); 128 | ppid = rand(); /* Choose an arbitrary value. */ 129 | stream = 1; 130 | 131 | sinfo->sinfo_ppid = ppid; 132 | sinfo->sinfo_stream = stream; 133 | 134 | outmessage.msg_iov->iov_base = message; 135 | outmessage.msg_iov->iov_len = (strlen(message) + 1); 136 | 137 | /* Send . This will create the association*/ 138 | test_sendmsg(clt_sk, &outmessage, 0, strlen(message)+1); 139 | 140 | memset(&inmessage, 0, sizeof(inmessage)); 141 | /* NOW initialize inmessage with enough space for DATA... */ 142 | big_buffer = test_malloc(REALLY_BIG); 143 | 144 | /* Let's do a test to do a recvmsg when we are not listening and 145 | * when we have no associations. 146 | */ 147 | iov.iov_base = big_buffer; 148 | iov.iov_len = REALLY_BIG; 149 | inmessage.msg_iov = &iov; 150 | inmessage.msg_iovlen = 1; 151 | inmessage.msg_control = incmsg; 152 | inmessage.msg_controllen = sizeof(incmsg); 153 | 154 | error = test_recvmsg(clt_sk, &inmessage, MSG_WAITALL); 155 | test_check_msg_notification(&inmessage, 156 | error, 157 | sizeof(struct sctp_assoc_change), 158 | SCTP_ASSOC_CHANGE, 159 | SCTP_COMM_UP); 160 | 161 | tst_resm(TPASS, "COMM_UP notification on client socket - SUCCESS"); 162 | 163 | error = test_recvmsg(acpt_sk, &inmessage, MSG_WAITALL); 164 | test_check_msg_notification(&inmessage, 165 | error, 166 | sizeof(struct sctp_assoc_change), 167 | SCTP_ASSOC_CHANGE, 168 | SCTP_COMM_UP); 169 | 170 | tst_resm(TPASS, "COMM_UP notification on server socket - SUCCESS"); 171 | 172 | #ifdef HAVE_SCTP_AUTH_NO_AUTH 173 | error = test_recvmsg(acpt_sk, &inmessage, MSG_WAITALL); 174 | test_check_msg_notification(&inmessage, 175 | error, 176 | sizeof(struct sctp_authkey_event), 177 | SCTP_AUTHENTICATION_EVENT, 178 | SCTP_AUTH_NO_AUTH); 179 | 180 | tst_resm(TPASS, "AUTH_NO_AUTH notification on server socket - SUCCESS"); 181 | #endif 182 | 183 | inmessage.msg_control = incmsg; 184 | inmessage.msg_controllen = sizeof(incmsg); 185 | error = test_recvmsg(acpt_sk, &inmessage, MSG_WAITALL); 186 | test_check_msg_data(&inmessage, error, strlen(message) + 1, 187 | MSG_EOR, stream, ppid); 188 | 189 | tst_resm(TPASS, "Data message on server socket - SUCCESS"); 190 | 191 | close(clt_sk); 192 | error = test_recvmsg(acpt_sk, &inmessage, MSG_WAITALL); 193 | test_check_msg_notification(&inmessage, 194 | error, 195 | sizeof(struct sctp_shutdown_event), 196 | SCTP_SHUTDOWN_EVENT, 197 | 0); 198 | 199 | tst_resm(TPASS, "SHUTDOWN notification on accepted socket - SUCCESS"); 200 | close(svr_sk); 201 | close(acpt_sk); 202 | 203 | free(big_buffer); 204 | return 0; 205 | } 206 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_initmsg_connect.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * When init timeout is set to zero, a connect () crashed the system. This case 6 | * tests the fix for the same. 7 | * 8 | * The SCTP implementation is free software; 9 | * you can redistribute it and/or modify it under the terms of 10 | * the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * The SCTP implementation is distributed in the hope that it 15 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 16 | * ************************ 17 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with GNU CC; see the file COPYING. If not, write to 22 | * the Free Software Foundation, 59 Temple Place - Suite 330, 23 | * Boston, MA 02111-1307, USA. 24 | * 25 | * Please send any bug reports or fixes you make to the 26 | * email address(es): 27 | * lksctp developers 28 | * 29 | * Or submit a bug report through the following website: 30 | * https://github.com/sctp/lksctp-tools/ 31 | * 32 | * 33 | * Any bugs reported given to us we will try to fix... any fixes shared will 34 | * be incorporated into the next SCTP release. 35 | * 36 | */ 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include /* for sockaddr_in */ 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | char *TCID = __FILE__; 52 | int TST_TOTAL = 1; 53 | int TST_CNT = 0; 54 | 55 | int 56 | main (int argc, char **argv) 57 | { 58 | int sk1, sk2, sk3, pf_class; 59 | socklen_t len; 60 | struct sockaddr_in lstn_addr, acpt_addr; 61 | struct sockaddr_in conn_addr; 62 | char * buffer_rcv; 63 | struct sctp_initmsg sinmsg; 64 | char *message = "Hello World!\n"; 65 | 66 | /* Rather than fflush() throughout the code, set stdout to 67 | * be unbuffered. 68 | */ 69 | setvbuf(stdout, NULL, _IONBF, 0); 70 | setvbuf(stderr, NULL, _IONBF, 0); 71 | 72 | /* Opening the socket*/ 73 | 74 | pf_class = PF_INET; 75 | 76 | sk1 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 77 | sk3 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 78 | 79 | conn_addr.sin_family = AF_INET; 80 | conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 81 | conn_addr.sin_port = htons(SCTP_TESTPORT_1); 82 | 83 | lstn_addr.sin_family = AF_INET; 84 | lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 85 | lstn_addr.sin_port = htons(SCTP_TESTPORT_1); 86 | 87 | test_bind(sk3, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); 88 | 89 | len = sizeof(struct sctp_initmsg); 90 | sinmsg.sinit_num_ostreams = 65535; 91 | sinmsg.sinit_max_instreams = 10; 92 | sinmsg.sinit_max_attempts = 1; 93 | sinmsg.sinit_max_init_timeo = 0; 94 | test_setsockopt(sk1, SCTP_INITMSG, &sinmsg, len); 95 | sinmsg.sinit_num_ostreams = 10; 96 | sinmsg.sinit_max_instreams = 65535; 97 | test_setsockopt(sk3, SCTP_INITMSG, &sinmsg, len); 98 | 99 | test_listen(sk3, 1); 100 | 101 | len = sizeof(struct sockaddr_in); 102 | test_connect(sk1, (struct sockaddr *) &conn_addr, len); 103 | 104 | sk2 = test_accept(sk3, (struct sockaddr *) &acpt_addr, &len); 105 | 106 | test_sctp_sendmsg(sk1, message, strlen(message) + 1, 107 | (struct sockaddr *)&conn_addr, len, 108 | 0, 0, 65534, 0, 0); 109 | 110 | buffer_rcv = test_malloc(100); 111 | test_recv(sk2, buffer_rcv, (strlen(message) + 1), MSG_NOSIGNAL); 112 | 113 | tst_resm(TPASS, "connect() with init timeout set to 0 - SUCCESS"); 114 | 115 | close (sk1); 116 | close (sk2); 117 | close (sk3); 118 | 119 | free(buffer_rcv); 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_nonblock.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This file has test cases to test the Non-Blocking mode of connect(), 6 | * accept() and recvmsg() calls. 7 | * 8 | * TEST1: Non blocking accept return EAGAIN if connect is not called 9 | * TEST2: Non blocking connect should return EINPROGRESS 10 | * TEST3: accept() passes when connect called in Non-blocking mode 11 | * TEST4: Non blocking recvmsg should return EAGAIN 12 | * TEST5: recvmsg() should succeed if data present to receive in non blocking 13 | * mode 14 | * 15 | * The SCTP implementation is free software; 16 | * you can redistribute it and/or modify it under the terms of 17 | * the GNU General Public License as published by 18 | * the Free Software Foundation; either version 2, or (at your option) 19 | * any later version. 20 | * 21 | * The SCTP implementation is distributed in the hope that it 22 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 23 | * ************************ 24 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | * See the GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with GNU CC; see the file COPYING. If not, write to 29 | * the Free Software Foundation, 59 Temple Place - Suite 330, 30 | * Boston, MA 02111-1307, USA. 31 | * 32 | * Please send any bug reports or fixes you make to the 33 | * email address(es): 34 | * lksctp developers 35 | * 36 | * Or submit a bug report through the following website: 37 | * https://github.com/sctp/lksctp-tools/ 38 | * 39 | * Any bugs reported given to us we will try to fix... any fixes shared will 40 | * be incorporated into the next SCTP release 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include /* for sockaddr_in */ 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | char *TCID = __FILE__; 60 | int TST_TOTAL = 5; 61 | int TST_CNT = 0; 62 | 63 | int 64 | main(int argc, char *argv[]) 65 | { 66 | int error,msg_count; 67 | socklen_t len; 68 | int sk,pf_class,lstn_sk,acpt_sk,flag,cflag,sflag; 69 | struct msghdr outmessage; 70 | struct msghdr inmessage; 71 | char *message = "hello, world!\n"; 72 | struct iovec iov_rcv; 73 | struct sctp_sndrcvinfo *sinfo; 74 | char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; 75 | struct cmsghdr *cmsg; 76 | struct iovec out_iov; 77 | char * buffer_rcv; 78 | char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; 79 | 80 | struct sockaddr_in conn_addr,lstn_addr,svr_addr; 81 | 82 | /* Rather than fflush() throughout the code, set stdout to 83 | * be unbufferd 84 | */ 85 | setvbuf(stdout, NULL, _IONBF, 0); 86 | setvbuf(stderr, NULL, _IONBF, 0); 87 | 88 | pf_class = PF_INET; 89 | 90 | sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 91 | 92 | lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 93 | 94 | conn_addr.sin_family = AF_INET; 95 | conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 96 | conn_addr.sin_port = htons(SCTP_TESTPORT_1); 97 | 98 | lstn_addr.sin_family = AF_INET; 99 | lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 100 | lstn_addr.sin_port = htons(SCTP_TESTPORT_1); 101 | 102 | /*Binding the listen socket*/ 103 | test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); 104 | 105 | /*Listening the socket*/ 106 | test_listen(lstn_sk, 10); 107 | 108 | len = sizeof(struct sockaddr_in); 109 | flag = MSG_NOSIGNAL; 110 | 111 | /*Setting server socket non-blocking*/ 112 | sflag = fcntl(lstn_sk, F_GETFL, 0); 113 | if (sflag < 0) 114 | tst_brkm(TBROK, tst_exit, "fcnt F_GETFL failed " 115 | "sflag:%d, errno:%d", sflag, errno); 116 | 117 | error = fcntl(lstn_sk, F_SETFL, sflag | O_NONBLOCK); 118 | if (error < 0) 119 | tst_brkm(TBROK, tst_exit, "fcnt F_SETFL failed " 120 | "error:%d, errno:%d", error, errno); 121 | 122 | /* TEST1: accept should return EAGAIN instead blocking. */ 123 | error = accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); 124 | if (error != -1 || errno != EAGAIN) 125 | tst_brkm(TBROK, tst_exit, "non-blocking accept " 126 | "error:%d, errno:%d", error, errno); 127 | 128 | tst_resm(TPASS, "non-blocking accept() - EAGAIN"); 129 | 130 | /* TEST2: Non Block connect should return EINPROGRESS */ 131 | /*Set client socket as non-blocking*/ 132 | cflag = fcntl(sk, F_GETFL, 0); 133 | if (cflag < 0) 134 | tst_brkm(TBROK, tst_exit, "fcnt F_GETFL failed " 135 | "cflag:%d, errno:%d", cflag, errno); 136 | 137 | error = fcntl(sk, F_SETFL, sflag | O_NONBLOCK); 138 | if (error < 0) 139 | tst_brkm(TBROK, tst_exit, "fcnt F_SETFL failed " 140 | "error:%d, errno:%d", error, errno); 141 | 142 | error = connect(sk, (const struct sockaddr *) &conn_addr, len); 143 | if (error != -1 || errno != EINPROGRESS) 144 | tst_brkm(TBROK, tst_exit, "non-blocking connect " 145 | "error:%d, errno:%d", error, errno); 146 | 147 | tst_resm(TPASS, "non-blocking connect() - EINPROGRESS"); 148 | 149 | /* TEST3: Now that connect() called, accept will succeed */ 150 | acpt_sk = accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); 151 | if (acpt_sk < 0) 152 | tst_brkm(TBROK, tst_exit, "accept after a non-blocking connect " 153 | "error:%d, errno:%d", error, errno); 154 | 155 | tst_resm(TPASS, "accept() after a non-blocking connect - SUCCESS"); 156 | 157 | memset(&outmessage, 0, sizeof(outmessage)); 158 | outmessage.msg_name = &svr_addr; 159 | outmessage.msg_namelen = sizeof(svr_addr); 160 | outmessage.msg_iov = &out_iov; 161 | outmessage.msg_iovlen = 1; 162 | outmessage.msg_control = outcmsg; 163 | outmessage.msg_controllen = sizeof(outcmsg); 164 | outmessage.msg_flags = 0; 165 | 166 | cmsg = CMSG_FIRSTHDR(&outmessage); 167 | cmsg->cmsg_level = IPPROTO_SCTP; 168 | cmsg->cmsg_type = SCTP_SNDRCV; 169 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 170 | outmessage.msg_controllen = cmsg->cmsg_len; 171 | sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); 172 | memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); 173 | 174 | outmessage.msg_iov->iov_base = message; 175 | outmessage.msg_iov->iov_len = strlen(message) + 1; 176 | 177 | memset(&inmessage, 0, sizeof(inmessage)); 178 | buffer_rcv = test_malloc(REALLY_BIG); 179 | 180 | iov_rcv.iov_base = buffer_rcv; 181 | iov_rcv.iov_len = REALLY_BIG; 182 | inmessage.msg_iov = &iov_rcv; 183 | inmessage.msg_iovlen = 1; 184 | inmessage.msg_control = incmsg; 185 | inmessage.msg_controllen = sizeof(incmsg); 186 | 187 | msg_count = strlen(message) + 1; 188 | 189 | /* TEST4: recvmsg() should return EAGAIN instead blocking */ 190 | error = recvmsg(sk, &inmessage, MSG_WAITALL); 191 | if ( error != -1 || errno != EAGAIN) 192 | tst_brkm(TBROK, tst_exit, "non-blocking recvmsg " 193 | "error:%d, errno:%d", error, errno); 194 | 195 | tst_resm(TPASS, "non-blocking recvmsg() - EAGAIN"); 196 | 197 | test_sendmsg(acpt_sk, &outmessage, flag, msg_count); 198 | 199 | /* TEST5: recvmsg() should succeed now as data is available. */ 200 | error = test_recvmsg(sk, &inmessage, flag); 201 | test_check_msg_data(&inmessage, error, msg_count, MSG_EOR, 0, 0); 202 | 203 | tst_resm(TPASS, "non-blocking recvmsg() when data is available - " 204 | "SUCCESS"); 205 | 206 | close(lstn_sk); 207 | close(acpt_sk); 208 | 209 | free(buffer_rcv); 210 | return 0; 211 | } 212 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_recvfrom.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This file has test cases to test the recvfrom () call for 1-1 style sockets 6 | * 7 | * TEST1: Bad socket descriptor 8 | * TEST2: Invalid socket 9 | * TEST3: Invalid message pointer 10 | * TEST4: On a listening socket 11 | * TEST5: Reading on a socket that received SHUTDOWN 12 | * TEST6: Reading the pending message on socket that received SHUTDOWN 13 | * TEST7: No more message and association is shutdown 14 | * 15 | * The SCTP implementation is free software; 16 | * you can redistribute it and/or modify it under the terms of 17 | * the GNU General Public License as published by 18 | * the Free Software Foundation; either version 2, or (at your option) 19 | * any later version. 20 | * 21 | * The SCTP implementation is distributed in the hope that it 22 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 23 | * ************************ 24 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | * See the GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with GNU CC; see the file COPYING. If not, write to 29 | * the Free Software Foundation, 59 Temple Place - Suite 330, 30 | * Boston, MA 02111-1307, USA. 31 | * 32 | * Please send any bug reports or fixes you make to the 33 | * email address(es): 34 | * lksctp developers 35 | * 36 | * Or submit a bug report through the following website: 37 | * https://github.com/sctp/lksctp-tools/ 38 | * 39 | * Any bugs reported given to us we will try to fix... any fixes shared will 40 | * be incorporated into the next SCTP release 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include /* for sockaddr_in */ 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | char *TCID = __FILE__; 60 | int TST_TOTAL = 7; 61 | int TST_CNT = 0; 62 | 63 | int 64 | main(int argc, char *argv[]) 65 | { 66 | int msg_count; 67 | socklen_t len; 68 | int sk,pf_class,lstn_sk,acpt_sk, flag; 69 | char *message = "hello, world!\n"; 70 | char *message_rcv; 71 | int count; 72 | int fd, err_no = 0; 73 | char filename[21]; 74 | 75 | struct sockaddr_in conn_addr,lstn_addr,svr_addr; 76 | 77 | /* Rather than fflush() throughout the code, set stdout to 78 | * be unbuffered. 79 | */ 80 | setvbuf(stdout, NULL, _IONBF, 0); 81 | setvbuf(stderr, NULL, _IONBF, 0); 82 | 83 | message_rcv = test_malloc(512); 84 | 85 | pf_class = PF_INET; 86 | 87 | sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 88 | 89 | lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 90 | 91 | conn_addr.sin_family = AF_INET; 92 | conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 93 | conn_addr.sin_port = htons(SCTP_TESTPORT_1); 94 | 95 | lstn_addr.sin_family = AF_INET; 96 | lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 97 | lstn_addr.sin_port = htons(SCTP_TESTPORT_1); 98 | 99 | /*Binding the listen socket*/ 100 | test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); 101 | 102 | /*Listening the socket*/ 103 | test_listen(lstn_sk, 10); 104 | 105 | len = sizeof(struct sockaddr_in); 106 | 107 | test_connect(sk, (struct sockaddr *) &conn_addr, len); 108 | 109 | acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); 110 | 111 | msg_count = (strlen(message) + 1); 112 | 113 | flag = MSG_NOSIGNAL; 114 | /*Sending the message*/ 115 | count = test_send(sk, message, msg_count, flag); 116 | 117 | /*recvfrom () TEST1: Bad socket descriptor, EBADF Expected error*/ 118 | count = recvfrom(-1, message_rcv, msg_count, flag, 119 | (struct sockaddr *)&svr_addr, &len); 120 | if (count != -1 || errno != EBADF) 121 | tst_brkm(TBROK, tst_exit, "recvfrom with a bad socket " 122 | "descriptor count:%d, errno:%d", count, errno); 123 | 124 | tst_resm(TPASS, "recvfrom() with a bad socket descriptor - EBADF"); 125 | 126 | /*recvfrom () TEST2: Invalid socket , ENOTSOCK Expected error*/ 127 | strcpy(filename, "/tmp/sctptest.XXXXXX"); 128 | fd = mkstemp(filename); 129 | if (fd == -1) 130 | tst_brkm(TBROK, tst_exit, "Failed to mkstemp %s: %s", 131 | filename, strerror(errno)); 132 | count = recvfrom(fd, message_rcv, msg_count, flag, 133 | (struct sockaddr *)&svr_addr, &len); 134 | if (count == -1) 135 | err_no = errno; 136 | close(fd); 137 | unlink(filename); 138 | if (count != -1 || err_no != ENOTSOCK) 139 | tst_brkm(TBROK, tst_exit, "recvfrom with invalid socket " 140 | "count:%d, errno:%d", count, err_no); 141 | 142 | tst_resm(TPASS, "recvfrom() with invalid socket - ENOTSOCK"); 143 | 144 | /*recvfrom () TEST3: Invalid message pointer EFAULT, Expected error*/ 145 | count = recvfrom(acpt_sk, (char *)-1, msg_count, flag, 146 | (struct sockaddr *)&svr_addr, &len); 147 | if (count != -1 || errno != EFAULT) 148 | tst_brkm(TBROK, tst_exit, "recvfrom with invalid message " 149 | "pointer count:%d, errno:%d", count, errno); 150 | 151 | tst_resm(TPASS, "recvfrom() with invalid message ptr - EFAULT"); 152 | 153 | /*TEST4: recvfrom on listening socket,ENOTCONN Expected error*/ 154 | count = recvfrom(lstn_sk, message_rcv, msg_count, flag, 155 | (struct sockaddr *)&svr_addr, &len); 156 | if (count != -1 || errno != ENOTCONN) 157 | tst_brkm(TBROK, tst_exit, "recvfrom on listening socket " 158 | "count:%d, errno:%d", count, errno); 159 | 160 | tst_resm(TPASS, "recvfrom() on listening socket - ENOTCONN"); 161 | 162 | count = test_send(acpt_sk, message, msg_count, flag); 163 | 164 | test_shutdown(sk, SHUT_WR); 165 | 166 | /*recvfrom () TEST5:reading on a socket that received SHUTDOWN*/ 167 | count = recvfrom(acpt_sk, message_rcv, msg_count, flag, 168 | (struct sockaddr *)&svr_addr, &len); 169 | if (count < 0) 170 | tst_brkm(TBROK, tst_exit, "recvfrom on a socket that has " 171 | "received shutdown count:%d, errno:%d", count, errno); 172 | 173 | tst_resm(TPASS, "recvfrom() on a socket that has received shutdown - " 174 | "EOF"); 175 | 176 | /*recvfrom () TEST6:reading the pending message on socket that sent 177 | SHUTDOWN*/ 178 | count = recvfrom(sk, message_rcv, msg_count, flag, 179 | (struct sockaddr *)&svr_addr, &len); 180 | if (count < 0) 181 | tst_brkm(TBROK, tst_exit, "recvfrom on a socket with pending " 182 | "message that has sent shutdown count:%d, errno:%d", 183 | count, errno); 184 | 185 | tst_resm(TPASS, "recvfrom() on a socket with pending message that has " 186 | "sent shutdown - SUCCESS"); 187 | 188 | /*recvfrom () TEST7: No more message and association is shutdown, 189 | ENOTCONN Expected error*/ 190 | count = recvfrom(sk, message_rcv, msg_count, flag, 191 | (struct sockaddr *)&svr_addr, &len); 192 | if (count != -1 || errno != ENOTCONN) 193 | tst_brkm(TBROK, tst_exit, "recvfrom on a socket with no " 194 | "pending messages and has sent shutdown count:%d, " 195 | "errno:%d", count, errno); 196 | 197 | tst_resm(TPASS, "recvfrom() on a socket with no pending messages and " 198 | " has sent shutdown - ENOTCONN"); 199 | 200 | close(sk); 201 | close(lstn_sk); 202 | close(acpt_sk); 203 | 204 | free(message_rcv); 205 | return 0; 206 | } 207 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_recvmsg.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This file has test cases to test the recvmsg() call for 1-1 style sockets 6 | * 7 | * TEST1: Bad socket descriptor 8 | * TEST2: Invalid socket 9 | * TEST3: Invalid iovec pointer 10 | * TEST4: Invalid msghdr pointer 11 | * TEST5: On a listening socket 12 | * TEST6: Reading on a socket that received SHUTDOWN 13 | * TEST7: Reading the pending message socket that received SHUTDOWN 14 | * TEST8: No more message and association is shutdown 15 | * 16 | * The SCTP implementation is free software; 17 | * you can redistribute it and/or modify it under the terms of 18 | * the GNU General Public License as published by 19 | * the Free Software Foundation; either version 2, or (at your option) 20 | * any later version. 21 | * 22 | * The SCTP implementation is distributed in the hope that it 23 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 24 | * ************************ 25 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 26 | * See the GNU General Public License for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with GNU CC; see the file COPYING. If not, write to 30 | * the Free Software Foundation, 59 Temple Place - Suite 330, 31 | * Boston, MA 02111-1307, USA. 32 | * 33 | * Please send any bug reports or fixes you make to the 34 | * email address(es): 35 | * lksctp developers 36 | * 37 | * Or submit a bug report through the following website: 38 | * https://github.com/sctp/lksctp-tools/ 39 | * 40 | * Any bugs reported given to us we will try to fix... any fixes shared will 41 | * be incorporated into the next SCTP release 42 | * 43 | */ 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include /* for sockaddr_in */ 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | 60 | char *TCID = __FILE__; 61 | int TST_TOTAL = 8; 62 | int TST_CNT = 0; 63 | 64 | int 65 | main(int argc, char *argv[]) 66 | { 67 | socklen_t len; 68 | int sk,pf_class,lstn_sk,acpt_sk; 69 | int flag = 0; 70 | int fd, err_no = 0; 71 | char filename[21]; 72 | struct msghdr inmessage; 73 | char *message = "hello, world!\n"; 74 | struct iovec iov_rcv; 75 | int count; 76 | char * buffer_rcv; 77 | char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; 78 | char *message1 = "hello, world!\n"; 79 | 80 | struct sockaddr_in conn_addr,lstn_addr,svr_addr; 81 | 82 | /* Rather than fflush() throughout the code, set stdout to 83 | * be unbuffered. 84 | */ 85 | setvbuf(stdout, NULL, _IONBF, 0); 86 | setvbuf(stderr, NULL, _IONBF, 0); 87 | 88 | pf_class = PF_INET; 89 | 90 | sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 91 | 92 | lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 93 | 94 | conn_addr.sin_family = AF_INET; 95 | conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 96 | conn_addr.sin_port = htons(SCTP_TESTPORT_1); 97 | 98 | lstn_addr.sin_family = AF_INET; 99 | lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 100 | lstn_addr.sin_port = htons(SCTP_TESTPORT_1); 101 | 102 | /*Binding the listen socket*/ 103 | test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); 104 | 105 | /*Listening the socket*/ 106 | test_listen(lstn_sk, 10); 107 | 108 | len = sizeof(struct sockaddr_in); 109 | 110 | test_connect(sk, (struct sockaddr *) &conn_addr, len); 111 | 112 | acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); 113 | 114 | memset(&inmessage, 0, sizeof(inmessage)); 115 | buffer_rcv = test_malloc(REALLY_BIG); 116 | 117 | iov_rcv.iov_base = buffer_rcv; 118 | iov_rcv.iov_len = REALLY_BIG; 119 | inmessage.msg_iov = &iov_rcv; 120 | inmessage.msg_iovlen = 1; 121 | inmessage.msg_control = incmsg; 122 | inmessage.msg_controllen = sizeof(incmsg); 123 | 124 | /*recvmsg () TEST1: Bad socket descriptor, EBADF Expected error*/ 125 | count = recvmsg(-1, &inmessage, flag); 126 | if (count != -1 || errno != EBADF) 127 | tst_brkm(TBROK, tst_exit, "recvmsg with a bad socket " 128 | "descriptor count:%d, errno:%d", count, errno); 129 | 130 | tst_resm(TPASS, "recvmsg() with a bad socket descriptor - EBADF"); 131 | 132 | /*recvmsg () TEST2: Invalid socket , ENOTSOCK Expected error*/ 133 | strcpy(filename, "/tmp/sctptest.XXXXXX"); 134 | fd = mkstemp(filename); 135 | if (fd == -1) 136 | tst_brkm(TBROK, tst_exit, "Failed to mkstemp %s: %s", 137 | filename, strerror(errno)); 138 | count = recvmsg(fd, &inmessage, flag); 139 | if (count == -1) 140 | err_no = errno; 141 | close(fd); 142 | unlink(filename); 143 | if (count != -1 || err_no != ENOTSOCK) 144 | tst_brkm(TBROK, tst_exit, "recvmsg with invalid socket " 145 | "count:%d, errno:%d", count, err_no); 146 | 147 | tst_resm(TPASS, "recvmsg() with invalid socket - ENOTSOCK"); 148 | 149 | /*recvmsg () TEST3: Invalid iovec pointer EFAULT, Expected error*/ 150 | inmessage.msg_iov = (struct iovec *)-1; 151 | count = recvmsg(acpt_sk, &inmessage, flag); 152 | if (count != -1 || errno != EFAULT) 153 | tst_brkm(TBROK, tst_exit, "recvmsg with invalid iovec " 154 | "pointer count:%d, errno:%d", count, errno); 155 | 156 | tst_resm(TPASS, "recvmsg() with invalid iovec ptr - EFAULT"); 157 | 158 | inmessage.msg_iov = &iov_rcv; 159 | 160 | /*recvmsg () TEST4: Invalid msghdr pointer EFAULT, Expected error*/ 161 | count = recvmsg(acpt_sk, (struct msghdr *)-1, flag); 162 | if (count != -1 || errno != EFAULT) 163 | tst_brkm(TBROK, tst_exit, "recvmsg with invalid msghdr " 164 | "pointer count:%d, errno:%d", count, errno); 165 | 166 | tst_resm(TPASS, "recvmsg() with invalid msghdr ptr - EFAULT"); 167 | 168 | /*recvmsg () TEST5:recvmsg on listening socket,ENOTCONN Expected error*/ 169 | count = recvmsg(lstn_sk, &inmessage, flag); 170 | if (count != -1 || errno != ENOTCONN) 171 | tst_brkm(TBROK, tst_exit, "recvmsg on listening socket " 172 | "count:%d, errno:%d", count, errno); 173 | 174 | tst_resm(TPASS, "recvmsg() on listening socket - ENOTCONN"); 175 | 176 | count = test_send(acpt_sk, message1, strlen(message), 0); 177 | 178 | test_shutdown(sk, SHUT_WR); 179 | 180 | flag = MSG_NOSIGNAL; 181 | /*recvmsg () TEST6:reading on a socket that received SHUTDOWN*/ 182 | count = recvmsg(acpt_sk, &inmessage, flag); 183 | if (count < 0) 184 | tst_brkm(TBROK, tst_exit, "recvmsg on a socket that has " 185 | "received shutdown count:%d, errno:%d", count, errno); 186 | 187 | tst_resm(TPASS, "recvmsg() on a socket that has received shutdown - " 188 | "EOF"); 189 | 190 | /*recvmsg () TEST7:reading the pending message socket that sent 191 | SHUTDOWN*/ 192 | count = recvmsg(sk, &inmessage, flag); 193 | if (count < 0) 194 | tst_brkm(TBROK, tst_exit, "recvmsg on a socket with pending " 195 | "message that has sent shutdown count:%d, errno:%d", 196 | count, errno); 197 | 198 | tst_resm(TPASS, "recvmsg() on a socket with pending message that has " 199 | "sent shutdown - SUCCESS"); 200 | 201 | /*recvmsg () TEST8: No more message and association is shutdown, 202 | ENOTCONN Expected error*/ 203 | count = recvmsg(sk, &inmessage, flag); 204 | if (count != -1 || errno != ENOTCONN) 205 | tst_brkm(TBROK, tst_exit, "recvmsg on a socket with no " 206 | "pending messages and has sent shutdown count:%d, " 207 | "errno:%d", count, errno); 208 | 209 | tst_resm(TPASS, "recvmsg() on a socket with no pending messages and " 210 | " has sent shutdown - ENOTCONN"); 211 | 212 | close(sk); 213 | close(lstn_sk); 214 | close(acpt_sk); 215 | 216 | free(buffer_rcv); 217 | return 0; 218 | } 219 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_rtoinfo.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This file has test cases to test the getsockopt () and sectsockopt () with 6 | * SCTP_RTOINFO option on 1-1 style socket 7 | * 8 | * This program first gets the default values using getsockopt(). It also sets 9 | * the value using setsockopt() and gets the set value using getsockopt(). 10 | * A comparison between set values and get values are performed. 11 | * 12 | * The SCTP implementation is free software; 13 | * you can redistribute it and/or modify it under the terms of 14 | * the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2, or (at your option) 16 | * any later version. 17 | * 18 | * The SCTP implementation is distributed in the hope that it 19 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 20 | * ************************ 21 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | * See the GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with GNU CC; see the file COPYING. If not, write to 26 | * the Free Software Foundation, 59 Temple Place - Suite 330, 27 | * Boston, MA 02111-1307, USA. 28 | * 29 | * Please send any bug reports or fixes you make to the 30 | * email address(es): 31 | * lksctp developers 32 | * 33 | * Or submit a bug report through the following website: 34 | * https://github.com/sctp/lksctp-tools/ 35 | * 36 | * Any bugs reported given to us we will try to fix... any fixes shared will 37 | * be incorporated into the next SCTP release 38 | * 39 | */ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include /* for sockaddr_in */ 50 | #include /* for sockaddr_in6 */ 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | char *TCID = __FILE__; 57 | int TST_TOTAL = 3; 58 | int TST_CNT = 0; 59 | 60 | int 61 | main(void) 62 | { 63 | 64 | int sd, ret; 65 | socklen_t len; 66 | struct sctp_rtoinfo srtoinfo; /*setting the variables*/ 67 | struct sctp_rtoinfo grtoinfo; /*Getting the variables*/ 68 | 69 | sd = test_socket (PF_INET, SOCK_STREAM, IPPROTO_SCTP); 70 | 71 | len = sizeof(struct sctp_rtoinfo); 72 | 73 | /*TEST1 Getting the default values using getsockopt()*/ 74 | ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len); 75 | if (ret < 0) 76 | tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO " 77 | "ret:%d, errno:%d", ret, errno); 78 | 79 | tst_resm(TPASS, "getsockopt() SCTP_RTOINFO - SUCCESS"); 80 | 81 | /*Assigning the values to RTO initial and max and min bounds*/ 82 | srtoinfo.srto_initial=60; 83 | srtoinfo.srto_max=100; 84 | srtoinfo.srto_min=40; 85 | srtoinfo.srto_assoc_id = 0; 86 | 87 | /*TEST2 Setting the values using setsockopt()*/ 88 | ret = setsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &srtoinfo, 89 | sizeof(struct sctp_rtoinfo)); 90 | if (ret < 0) 91 | tst_brkm(TBROK, tst_exit, "setsockopt SCTP_RTOINFO " 92 | "ret:%d, errno:%d", ret, errno); 93 | 94 | tst_resm(TPASS, "setsockopt() SCTP_RTOINFO - SUCCESS"); 95 | 96 | /*Getting the values which are set using setsockopt()*/ 97 | ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len); 98 | if (ret < 0) 99 | tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO " 100 | "ret:%d, errno:%d", ret, errno); 101 | 102 | /* TEST3 Compare the get values with the set values. */ 103 | if (srtoinfo.srto_initial != grtoinfo.srto_initial && 104 | srtoinfo.srto_max != grtoinfo.srto_max && 105 | srtoinfo.srto_min != grtoinfo.srto_min) 106 | tst_brkm(TBROK, tst_exit, "setsockopt/getsockopt SCTP_RTOINFO " 107 | "compare failed"); 108 | 109 | tst_resm(TPASS, "setsockopt()/getsockopt SCTP_RTOINFO compare - " 110 | "SUCCESS"); 111 | 112 | close(sd); 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_sendto.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This file has test cases to test the sendto () call 6 | * for 1-1 style sockets 7 | * 8 | * TEST1: Sending data from client socket to server socket 9 | * TEST2: Sending data from accept (server) socket to client socket 10 | * TEST3: Sending data from unconnected client socket to server 11 | * TEST4: sending partial data from a buffer 12 | * 13 | * The SCTP implementation is free software; 14 | * you can redistribute it and/or modify it under the terms of 15 | * the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2, or (at your option) 17 | * any later version. 18 | * 19 | * The SCTP implementation is distributed in the hope that it 20 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 21 | * ************************ 22 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | * See the GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with GNU CC; see the file COPYING. If not, write to 27 | * the Free Software Foundation, 59 Temple Place - Suite 330, 28 | * Boston, MA 02111-1307, USA. 29 | * 30 | * Please send any bug reports or fixes you make to the 31 | * email address(es): 32 | * lksctp developers 33 | * 34 | * Or submit a bug report through the following website: 35 | * https://github.com/sctp/lksctp-tools/ 36 | * 37 | * Any bugs reported given to us we will try to fix... any fixes shared will 38 | * be incorporated into the next SCTP release 39 | */ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include /* for sockaddr_in */ 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | char *TCID = __FILE__; 57 | int TST_TOTAL = 4; 58 | int TST_CNT = 0; 59 | 60 | int 61 | main(int argc, char *argv[]) 62 | { 63 | int msg_count; 64 | socklen_t len; 65 | int sk,sk1,pf_class,lstn_sk,acpt_sk,flag; 66 | char *message = "hello, world!\n"; 67 | char *message_rcv; 68 | int count; 69 | 70 | struct sockaddr_in conn_addr,lstn_addr,svr_addr; 71 | 72 | /* Rather than fflush() throughout the code, set stdout to 73 | * be unbufferd 74 | */ 75 | setvbuf(stdout, NULL, _IONBF, 0); 76 | setvbuf(stderr, NULL, _IONBF, 0); 77 | 78 | pf_class = PF_INET; 79 | 80 | sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 81 | 82 | lstn_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 83 | 84 | message_rcv = test_malloc(512); 85 | conn_addr.sin_family = AF_INET; 86 | conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 87 | conn_addr.sin_port = htons(SCTP_TESTPORT_1); 88 | 89 | lstn_addr.sin_family = AF_INET; 90 | lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 91 | lstn_addr.sin_port = htons(SCTP_TESTPORT_1); 92 | 93 | /*Binding the listen socket*/ 94 | test_bind(lstn_sk, (struct sockaddr *) &lstn_addr, sizeof(lstn_addr)); 95 | 96 | /*Listening the socket*/ 97 | test_listen(lstn_sk, 10); 98 | 99 | len = sizeof(struct sockaddr_in); 100 | flag = MSG_NOSIGNAL; 101 | 102 | test_connect(sk, (struct sockaddr *) &conn_addr, len); 103 | 104 | acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); 105 | 106 | msg_count = strlen(message) + 1; 107 | 108 | /*sendto() TEST1: Sending data from client socket to server socket*/ 109 | count = sendto(sk, message, msg_count, flag, 110 | (const struct sockaddr *) &conn_addr, len); 111 | if (count != msg_count) 112 | tst_brkm(TBROK, tst_exit, "sendto from client to server " 113 | "count:%d, errno:%d", count, errno); 114 | 115 | tst_resm(TPASS, "sendto() from client to server - SUCCESS"); 116 | 117 | test_recv(acpt_sk, message_rcv, msg_count, flag); 118 | 119 | strncpy(message_rcv,"\0",512); 120 | 121 | /*sendto() TEST2: Sending data from accept socket to client socket*/ 122 | count = sendto(acpt_sk, message, msg_count, flag, 123 | (const struct sockaddr *) &svr_addr, len); 124 | if (count != msg_count) 125 | tst_brkm(TBROK, tst_exit, "sendto from accept socket to client " 126 | "count:%d, errno:%d", count, errno); 127 | 128 | tst_resm(TPASS, "sendto() from accept socket to client - SUCCESS"); 129 | 130 | test_recv(sk, message_rcv, msg_count, flag); 131 | 132 | close(sk); 133 | close(acpt_sk); 134 | 135 | sk1 = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP); 136 | 137 | /*sendto() TEST3: Sending data from unconnected client socket to 138 | server socket*/ 139 | count = sendto(sk1, message, msg_count, flag, 140 | (const struct sockaddr *) &conn_addr, len); 141 | if (count != msg_count) 142 | tst_brkm(TBROK, tst_exit, "sendto from unconnected client to " 143 | "server count:%d, errno:%d", count, errno); 144 | 145 | tst_resm(TPASS, "sendto() from unconnected client to server - SUCCESS"); 146 | 147 | acpt_sk = test_accept(lstn_sk, (struct sockaddr *)&svr_addr, &len); 148 | 149 | test_recv(acpt_sk, message_rcv, msg_count, flag); 150 | 151 | /*send() TEST4: Sending less number of data from the buffer*/ 152 | /*Sending only 5 bytes so that only hello is received*/ 153 | test_sendto(sk1, message, 5, flag, (const struct sockaddr *)&conn_addr, 154 | len); 155 | test_recv(acpt_sk, message_rcv, 5, flag); 156 | 157 | tst_resm(TPASS, "sendto() partial data from a buffer - SUCCESS"); 158 | 159 | close(sk1); 160 | close(lstn_sk); 161 | close(acpt_sk); 162 | 163 | free(message_rcv); 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /src/func_tests/test_1_to_1_threads.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * Copyright (c) 2003 Hewlett-Packard Development Company, L.P 3 | * (C) Copyright IBM Corp. 2004 4 | * 5 | * This file does send and receive for 500 threads on a unique association for 6 | * THREAD_SND_RCV_LOOPS = 10 many times. To change the number of threads 7 | * change the THREADS valuen and loop change the THREAD_SND_RCV_LOOPS. 8 | * 9 | * The SCTP implementation is free software; 10 | * you can redistribute it and/or modify it under the terms of 11 | * the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2, or (at your option) 13 | * any later version. 14 | * 15 | * The SCTP implementation is distributed in the hope that it 16 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 17 | * ************************ 18 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GNU CC; see the file COPYING. If not, write to 23 | * the Free Software Foundation, 59 Temple Place - Suite 330, 24 | * Boston, MA 02111-1307, USA. 25 | * 26 | * Please send any bug reports or fixes you make to the 27 | * email address(es): 28 | * lksctp developers 29 | * 30 | * Or submit a bug report through the following website: 31 | * https://github.com/sctp/lksctp-tools/ 32 | * 33 | * Any bugs reported given to us we will try to fix... any fixes shared will 34 | * be incorporated into the next SCTP release 35 | * 36 | */ 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include /* for sockaddr_in */ 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | #define THREADS 10 /* FIXME should be 500 instead of 10 */ 54 | #define THREAD_SND_RCV_LOOPS 10 55 | 56 | char *TCID = __FILE__; 57 | int TST_TOTAL = 1; 58 | int TST_CNT = 0; 59 | 60 | int client_sk; 61 | int server_sk; 62 | int acpt_sk; 63 | struct sockaddr_in conn_addr; 64 | char *message = "hello, world!\n"; 65 | 66 | void 67 | t_recv(void) { 68 | int cnt; 69 | struct msghdr inmessage; 70 | struct iovec iov; 71 | char incmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; 72 | char * buffer; 73 | 74 | memset(&inmessage, 0, sizeof(inmessage)); 75 | buffer = test_malloc(100); 76 | 77 | iov.iov_base = buffer; 78 | iov.iov_len = 100; 79 | inmessage.msg_iov = &iov; 80 | inmessage.msg_iovlen = 1; 81 | inmessage.msg_control = incmsg; 82 | inmessage.msg_controllen = sizeof(incmsg); 83 | 84 | cnt = test_recvmsg(acpt_sk,&inmessage, MSG_WAITALL); 85 | test_check_msg_data(&inmessage, cnt, strlen(message) + 1, MSG_EOR, 86 | 0, 0); 87 | free(buffer); 88 | } 89 | 90 | void 91 | t_send(void) { 92 | struct msghdr outmessage; 93 | struct sctp_sndrcvinfo *sinfo; 94 | struct cmsghdr *cmsg; 95 | struct iovec out_iov; 96 | char outcmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; 97 | 98 | memset(&outmessage, 0, sizeof(outmessage)); 99 | outmessage.msg_name = &conn_addr; 100 | outmessage.msg_namelen = sizeof(conn_addr); 101 | outmessage.msg_iov = &out_iov; 102 | outmessage.msg_iovlen = 1; 103 | outmessage.msg_control = outcmsg; 104 | outmessage.msg_controllen = sizeof(outcmsg); 105 | outmessage.msg_flags = 0; 106 | 107 | cmsg = CMSG_FIRSTHDR(&outmessage); 108 | cmsg->cmsg_level = IPPROTO_SCTP; 109 | cmsg->cmsg_type = SCTP_SNDRCV; 110 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 111 | outmessage.msg_controllen = cmsg->cmsg_len; 112 | 113 | sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); 114 | memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); 115 | outmessage.msg_iov->iov_base = message; 116 | outmessage.msg_iov->iov_len = (strlen(message) + 1); 117 | 118 | test_sendmsg(client_sk, &outmessage, 0, strlen(message)+1); 119 | } 120 | 121 | void *relay(void *arg) 122 | { 123 | int id = *(int *) arg; 124 | 125 | if (id == 0) { 126 | t_send(); 127 | } else { 128 | t_recv(); 129 | t_send(); 130 | } 131 | 132 | pthread_exit(NULL); 133 | } 134 | 135 | int 136 | main(void) 137 | { 138 | 139 | int cnt,i; 140 | int pth[THREADS]; 141 | pthread_t thread[THREADS]; 142 | int status; 143 | int exit_status; 144 | void * result; 145 | pthread_attr_t attr; 146 | struct sockaddr_in lstn_addr; 147 | socklen_t len = sizeof(struct sockaddr_in); 148 | struct sockaddr_in svr_addr; 149 | 150 | pthread_attr_init(&attr); 151 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); 152 | 153 | server_sk = test_socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP); 154 | client_sk = test_socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP); 155 | 156 | lstn_addr.sin_family = AF_INET; 157 | lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 158 | lstn_addr.sin_port = htons(SCTP_TESTPORT_1); 159 | 160 | conn_addr.sin_family = AF_INET; 161 | conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK; 162 | conn_addr.sin_port = htons(SCTP_TESTPORT_1); 163 | 164 | test_bind(server_sk, (struct sockaddr *)&lstn_addr, 165 | sizeof(struct sockaddr_in)); 166 | 167 | test_listen(server_sk,10); 168 | 169 | test_connect(client_sk,(struct sockaddr *)&conn_addr,len); 170 | 171 | acpt_sk = test_accept(server_sk, (struct sockaddr *)&svr_addr, &len); 172 | 173 | for ( i = 0; i < THREAD_SND_RCV_LOOPS; i++ ) { 174 | for (cnt = 0; cnt < THREADS; cnt++) { 175 | pth[cnt] = cnt; 176 | status = pthread_create(&thread[cnt], &attr, relay, &pth[cnt]); 177 | if (status) 178 | tst_brkm(TBROK, tst_exit, "pthread_create " 179 | "failed status:%d, errno:%d", status, 180 | errno); 181 | } 182 | 183 | pthread_attr_destroy(&attr); 184 | for (cnt = 0; cnt < THREADS ; cnt++) { 185 | exit_status = pthread_join (thread[cnt], &result); 186 | if (exit_status == -1) 187 | tst_brkm(TBROK, tst_exit, "pthread_join " 188 | "Thread #%d exited with status:%d", 189 | cnt, exit_status); 190 | } 191 | } 192 | 193 | tst_resm(TPASS, "send and receive data across multiple threads - " 194 | "SUCCESS"); 195 | 196 | return 0; 197 | } 198 | -------------------------------------------------------------------------------- /src/func_tests/test_autoclose.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * (C) Copyright IBM Corp. 2001, 2003 3 | * Copyright (c) 1999-2000 Cisco, Inc. 4 | * Copyright (c) 1999-2001 Motorola, Inc. 5 | * Copyright (c) 2001 Intel Corp. 6 | * Copyright (c) 2001 Nokia, Inc. 7 | * 8 | * The SCTP implementation is free software; 9 | * you can redistribute it and/or modify it under the terms of 10 | * the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2, or (at your option) 12 | * any later version. 13 | * 14 | * The SCTP implementation is distributed in the hope that it 15 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 16 | * ************************ 17 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with GNU CC; see the file COPYING. If not, write to 22 | * the Free Software Foundation, 59 Temple Place - Suite 330, 23 | * Boston, MA 02111-1307, USA. 24 | * 25 | * Please send any bug reports or fixes you make to the 26 | * email address(es): 27 | * lksctp developers 28 | * 29 | * Or submit a bug report through the following website: 30 | * https://github.com/sctp/lksctp-tools/ 31 | * 32 | * Any bugs reported to us we will try to fix... any fixes shared will 33 | * be incorporated into the next SCTP release. 34 | * 35 | * Written or modified by: 36 | * Sridhar Samudrala 37 | */ 38 | 39 | /* This is a Functional Test to verify autoclose functionality and the 40 | * socket option SCTP_AUTOCLOSE that can be used to specify the duration in 41 | * which an idle association is automatically closed. 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | char *TCID = __FILE__; 57 | int TST_TOTAL = 1; 58 | int TST_CNT = 0; 59 | 60 | int 61 | main(int argc, char *argv[]) 62 | { 63 | int sk1, sk2; 64 | sockaddr_storage_t loop1, loop2; 65 | struct msghdr inmessage, outmessage; 66 | struct iovec iov, out_iov; 67 | int error; 68 | char *big_buffer; 69 | char *message = "hello, world!\n"; 70 | uint32_t autoclose; 71 | 72 | /* Rather than fflush() throughout the code, set stdout to 73 | * be unbuffered. 74 | */ 75 | setvbuf(stdout, NULL, _IONBF, 0); 76 | 77 | loop1.v4.sin_family = AF_INET; 78 | loop1.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK; 79 | loop1.v4.sin_port = htons(SCTP_TESTPORT_1); 80 | 81 | loop2.v4.sin_family = AF_INET; 82 | loop2.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK; 83 | loop2.v4.sin_port = htons(SCTP_TESTPORT_2); 84 | 85 | /* Create the two endpoints which will talk to each other. */ 86 | sk1 = test_socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); 87 | sk2 = test_socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); 88 | 89 | /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */ 90 | test_enable_assoc_change(sk1); 91 | test_enable_assoc_change(sk2); 92 | 93 | /* Bind these sockets to the test ports. */ 94 | test_bind(sk1, &loop1.sa, sizeof(loop1)); 95 | test_bind(sk2, &loop2.sa, sizeof(loop2)); 96 | 97 | /* Mark sk2 as being able to accept new associations. */ 98 | test_listen(sk2, 1); 99 | 100 | /* Set the autoclose duration for the associations created on sk1 101 | * and sk2 to be 5 seconds. 102 | */ 103 | autoclose = 5; 104 | test_setsockopt(sk1, SCTP_AUTOCLOSE, &autoclose, sizeof(autoclose)); 105 | test_setsockopt(sk2, SCTP_AUTOCLOSE, &autoclose, sizeof(autoclose)); 106 | 107 | /* Send the first message. This will create the association. */ 108 | memset(&outmessage, 0, sizeof(outmessage)); 109 | outmessage.msg_name = &loop2; 110 | outmessage.msg_namelen = sizeof(loop2); 111 | outmessage.msg_iov = &out_iov; 112 | outmessage.msg_iovlen = 1; 113 | outmessage.msg_iov->iov_base = message; 114 | outmessage.msg_iov->iov_len = strlen(message) + 1; 115 | 116 | test_sendmsg(sk1, &outmessage, 0, strlen(message)+1); 117 | 118 | /* Initialize inmessage for all receives. */ 119 | big_buffer = test_malloc(REALLY_BIG); 120 | memset(&inmessage, 0, sizeof(inmessage)); 121 | iov.iov_base = big_buffer; 122 | iov.iov_len = REALLY_BIG; 123 | inmessage.msg_iov = &iov; 124 | inmessage.msg_iovlen = 1; 125 | inmessage.msg_control = NULL; 126 | 127 | /* Get the communication up message on sk2. */ 128 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); 129 | test_check_msg_notification(&inmessage, error, 130 | sizeof(struct sctp_assoc_change), 131 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); 132 | 133 | /* Get the communication up message on sk1. */ 134 | error = test_recvmsg(sk1, &inmessage, MSG_WAITALL); 135 | test_check_msg_notification(&inmessage, error, 136 | sizeof(struct sctp_assoc_change), 137 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); 138 | 139 | /* Get the first message which was sent. */ 140 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); 141 | test_check_msg_data(&inmessage, error, strlen(message) + 1, 142 | MSG_EOR|MSG_CTRUNC, 0, 0); 143 | 144 | tst_resm(TINFO, "Waiting for the associations to close automatically " 145 | "in 5 secs"); 146 | 147 | /* Get the shutdown complete notification from sk1. */ 148 | error = test_recvmsg(sk1, &inmessage, MSG_WAITALL); 149 | test_check_msg_notification(&inmessage, error, 150 | sizeof(struct sctp_assoc_change), 151 | SCTP_ASSOC_CHANGE, SCTP_SHUTDOWN_COMP); 152 | 153 | /* Get the shutdown complete notification from sk2. */ 154 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); 155 | test_check_msg_notification(&inmessage, error, 156 | sizeof(struct sctp_assoc_change), 157 | SCTP_ASSOC_CHANGE, SCTP_SHUTDOWN_COMP); 158 | 159 | tst_resm(TPASS, "Autoclose of associations"); 160 | 161 | /* Shut down the link. */ 162 | close(sk1); 163 | close(sk2); 164 | 165 | free(big_buffer); 166 | /* Indicate successful completion. */ 167 | return 0; 168 | } 169 | -------------------------------------------------------------------------------- /src/func_tests/test_recvmsg.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation 2 | * (C) Copyright IBM Corp. 2002, 2003 3 | * Copyright (c) 1999-2001 Motorola, Inc. 4 | * 5 | * This file is part of the SCTP kernel Implementation 6 | * 7 | * The SCTP implementation is free software; 8 | * you can redistribute it and/or modify it under the terms of 9 | * the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2, or (at your option) 11 | * any later version. 12 | * 13 | * The SCTP implementation is distributed in the hope that it 14 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied 15 | * ************************ 16 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with GNU CC; see the file COPYING. If not, write to 21 | * the Free Software Foundation, 59 Temple Place - Suite 330, 22 | * Boston, MA 02111-1307, USA. 23 | * 24 | * Please send any bug reports or fixes you make to the 25 | * email address(es): 26 | * lksctp developers 27 | * 28 | * Or submit a bug report through the following website: 29 | * https://github.com/sctp/lksctp-tools/ 30 | * 31 | * Written or modified by: 32 | * Sridhar Samudrala 33 | * 34 | * Any bugs reported to us we will try to fix... any fixes shared will 35 | * be incorporated into the next SCTP release. 36 | */ 37 | 38 | /* This is a kernel test to verify 39 | * 1. MSG_EOR flag is set correctly when a single message is read using multiple 40 | * recvmsg() calls. 41 | * 2. MSG_PEEK support. 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | char *TCID = __FILE__; 58 | int TST_TOTAL = 2; 59 | int TST_CNT = 0; 60 | 61 | int 62 | main(int argc, char *argv[]) 63 | { 64 | int svr_sk, clt_sk; 65 | struct sockaddr_in svr_loop, clt_loop; 66 | struct iovec iov, out_iov; 67 | struct msghdr inmessage, outmessage; 68 | char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; 69 | int error, msglen, i; 70 | char *big_buffer; 71 | void *msg_buf; 72 | 73 | /* Rather than fflush() throughout the code, set stdout to 74 | * be unbuffered. 75 | */ 76 | setvbuf(stdout, NULL, _IONBF, 0); 77 | 78 | /* Initialize the server and client addresses. */ 79 | svr_loop.sin_family = AF_INET; 80 | svr_loop.sin_addr.s_addr = SCTP_IP_LOOPBACK; 81 | svr_loop.sin_port = htons(SCTP_TESTPORT_1); 82 | clt_loop.sin_family = AF_INET; 83 | clt_loop.sin_addr.s_addr = SCTP_IP_LOOPBACK; 84 | clt_loop.sin_port = htons(SCTP_TESTPORT_2); 85 | 86 | /* Create and bind the server socket. */ 87 | svr_sk = test_socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); 88 | test_bind(svr_sk, (struct sockaddr *)&svr_loop, sizeof(svr_loop)); 89 | 90 | /* Mark server socket as being able to accept new associations. */ 91 | test_listen(svr_sk, 1); 92 | 93 | /* Create and bind the client sockets. */ 94 | clt_sk = test_socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); 95 | test_bind(clt_sk, (struct sockaddr *)&clt_loop, sizeof(clt_loop)); 96 | 97 | /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */ 98 | test_enable_assoc_change(svr_sk); 99 | test_enable_assoc_change(clt_sk); 100 | 101 | /* Send a message. This will create the association. */ 102 | memset(&outmessage, 0, sizeof(outmessage)); 103 | outmessage.msg_name = &svr_loop; 104 | outmessage.msg_namelen = sizeof(svr_loop); 105 | outmessage.msg_iov = &out_iov; 106 | outmessage.msg_iovlen = 1; 107 | msg_buf = test_build_msg(30000); 108 | outmessage.msg_iov->iov_base = msg_buf; 109 | outmessage.msg_iov->iov_len = 30000; 110 | test_sendmsg(clt_sk, &outmessage, 0, 30000); 111 | 112 | /* Initialize inmessage for all receives. */ 113 | big_buffer = test_malloc(REALLY_BIG); 114 | memset(&inmessage, 0, sizeof(inmessage)); 115 | iov.iov_base = big_buffer; 116 | iov.iov_len = 2000; 117 | inmessage.msg_iov = &iov; 118 | inmessage.msg_iovlen = 1; 119 | inmessage.msg_control = incmsg; 120 | 121 | /* Receive COMM_UP on clt_sk. */ 122 | inmessage.msg_controllen = sizeof(incmsg); 123 | error = test_recvmsg(clt_sk, &inmessage, 0); 124 | test_check_msg_notification(&inmessage, error, 125 | sizeof(struct sctp_assoc_change), 126 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); 127 | 128 | /* Receive COMM_UP on svr_sk. */ 129 | inmessage.msg_controllen = sizeof(incmsg); 130 | error = test_recvmsg(svr_sk, &inmessage, MSG_WAITALL); 131 | test_check_msg_notification(&inmessage, error, 132 | sizeof(struct sctp_assoc_change), 133 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); 134 | 135 | /* Read the 30000 byte message using multiple recvmsg() calls in a 136 | * loop with 2000 bytes per read. 137 | */ 138 | for (i = 0, msglen = 30000; i < 15; i++, msglen-=2000) { 139 | iov.iov_len = REALLY_BIG; 140 | inmessage.msg_controllen = sizeof(incmsg); 141 | error = test_recvmsg(svr_sk, &inmessage, MSG_PEEK); 142 | test_check_msg_data(&inmessage, error, msglen, 143 | MSG_EOR, 0, 0); 144 | 145 | iov.iov_len = 2000; 146 | inmessage.msg_controllen = sizeof(incmsg); 147 | error = test_recvmsg(svr_sk, &inmessage, MSG_WAITALL); 148 | test_check_msg_data(&inmessage, error, 2000, 149 | ((i==14)?MSG_EOR:0), 0, 0); 150 | } 151 | 152 | tst_resm(TPASS, "recvmsg with MSG_PEEK flag"); 153 | tst_resm(TPASS, "MSG_EOR in msg_flags set correctly"); 154 | 155 | close(svr_sk); 156 | close(clt_sk); 157 | 158 | free(big_buffer); 159 | free(msg_buf); 160 | /* Indicate successful completion. */ 161 | return 0; 162 | } 163 | -------------------------------------------------------------------------------- /src/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | 5 | SUBDIRS = netinet 6 | -------------------------------------------------------------------------------- /src/include/netinet/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | 5 | libcnetinetdir = $(includedir)/netinet 6 | 7 | 8 | ## FIXME: Your stuff here 9 | 10 | # Supposing this is part of the development package, header for our 11 | # API. 12 | include_HEADERS = 13 | 14 | libcnetinet_HEADERS = sctp.h 15 | -------------------------------------------------------------------------------- /src/include/netinet/sctp.h.in: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * sctp.h 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * Linux Kernel SCTP Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with SCTP in kernel. 12 | * 13 | * This header represents the structures and constants needed to support 14 | * the SCTP Extension to the Sockets API. 15 | * 16 | * (C) Copyright IBM Corp. 2001, 2004 17 | * Copyright (c) 1999-2000 Cisco, Inc. 18 | * Copyright (c) 1999-2001 Motorola, Inc. 19 | * 20 | * Written or modified by: 21 | * La Monte H.P. Yarroll 22 | * R. Stewart 23 | * K. Morneau 24 | * Q. Xie 25 | * Karl Knutson 26 | * Jon Grimm 27 | * Daisy Chang 28 | * Inaky Perez-Gonzalez 29 | * Sridhar Samudrala 30 | * Vlad Yasevich 31 | */ 32 | 33 | #ifndef __linux_sctp_h__ 34 | #define __linux_sctp_h__ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* Socket option layer for SCTP */ 46 | #ifndef SOL_SCTP 47 | #define SOL_SCTP 132 48 | #endif 49 | 50 | #ifndef IPPROTO_SCTP 51 | #define IPPROTO_SCTP 132 52 | #endif 53 | 54 | /* 9. Preprocessor constants */ 55 | #define HAVE_SCTP 56 | #define HAVE_KERNEL_SCTP 57 | #define HAVE_SCTP_MULTIBUF 58 | #define HAVE_SCTP_NOCONNECT 59 | #define HAVE_SCTP_PRSCTP 60 | #define HAVE_SCTP_ADDIP 61 | #define HAVE_SCTP_CANSET_PRIMARY 62 | 63 | #undef HAVE_SCTP_STREAM_RESET_EVENT 64 | #undef HAVE_SCTP_STREAM_RECONFIG 65 | #undef HAVE_SCTP_PEELOFF_FLAGS 66 | #undef HAVE_SCTP_PDAPI_EVENT_PDAPI_STREAM 67 | #undef HAVE_SCTP_PDAPI_EVENT_PDAPI_SEQ 68 | #undef HAVE_SCTP_SENDV 69 | #undef HAVE_SCTP_AUTH_NO_AUTH 70 | #undef HAVE_SCTP_SPP_IPV6_FLOWLABEL 71 | #undef HAVE_SCTP_SPP_DSCP 72 | 73 | int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags); 74 | 75 | int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt, 76 | sctp_assoc_t *id); 77 | 78 | int sctp_peeloff(int sd, sctp_assoc_t assoc_id); 79 | int sctp_peeloff_flags(int sd, sctp_assoc_t assoc_id, unsigned flags); 80 | 81 | /* Prototype for the library function sctp_opt_info defined in 82 | * API 7. Socket Options. 83 | */ 84 | int sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t *size); 85 | 86 | /* Get all peer address on a socket. This is a new SCTP API 87 | * described in the section 8.3 of the Sockets API Extensions for SCTP. 88 | * This is implemented using the getsockopt() interface. 89 | */ 90 | int sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **addrs); 91 | 92 | /* Frees all resources allocated by sctp_getpaddrs(). This is a new SCTP API 93 | * described in the section 8.4 of the Sockets API Extensions for SCTP. 94 | */ 95 | int sctp_freepaddrs(struct sockaddr *addrs); 96 | 97 | /* Get all locally bound address on a socket. This is a new SCTP API 98 | * described in the section 8.5 of the Sockets API Extensions for SCTP. 99 | * This is implemented using the getsockopt() interface. 100 | */ 101 | int sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **addrs); 102 | 103 | /* Frees all resources allocated by sctp_getladdrs(). This is a new SCTP API 104 | * described in the section 8.6 of the Sockets API Extensions for SCTP. 105 | */ 106 | int sctp_freeladdrs(struct sockaddr *addrs); 107 | 108 | /* This library function assists the user with the advanced features 109 | * of SCTP. This is a new SCTP API described in the section 8.7 of the 110 | * Sockets API Extensions for SCTP. This is implemented using the 111 | * sendmsg() interface. 112 | */ 113 | int sctp_sendmsg(int s, const void *msg, size_t len, struct sockaddr *to, 114 | socklen_t tolen, uint32_t ppid, uint32_t flags, 115 | uint16_t stream_no, uint32_t timetolive, uint32_t context); 116 | 117 | /* This library function assist the user with sending a message without 118 | * dealing directly with the CMSG header. 119 | */ 120 | int sctp_send(int s, const void *msg, size_t len, 121 | const struct sctp_sndrcvinfo *sinfo, int flags); 122 | 123 | /* This library function assists the user with the advanced features 124 | * of SCTP. This is a new SCTP API described in the section 8.8 of the 125 | * Sockets API Extensions for SCTP. This is implemented using the 126 | * recvmsg() interface. 127 | */ 128 | int sctp_recvmsg(int s, void *msg, size_t len, struct sockaddr *from, 129 | socklen_t *fromlen, struct sctp_sndrcvinfo *sinfo, 130 | int *msg_flags); 131 | 132 | /* Return the address length for an address family. */ 133 | int sctp_getaddrlen(sa_family_t family); 134 | 135 | 136 | #ifdef HAVE_SCTP_SENDV 137 | /* sendv infotype */ 138 | enum { 139 | SCTP_SENDV_NOINFO, 140 | SCTP_SENDV_SNDINFO, 141 | SCTP_SENDV_PRINFO, 142 | SCTP_SENDV_AUTHINFO, 143 | SCTP_SENDV_SPA 144 | }; 145 | 146 | /* sendv_flags */ 147 | #define SCTP_SEND_SNDINFO_VALID 0x1 148 | #define SCTP_SEND_PRINFO_VALID 0x2 149 | #define SCTP_SEND_AUTHINFO_VALID 0x4 150 | #endif 151 | 152 | struct sctp_sendv_spa { 153 | uint32_t sendv_flags; 154 | struct sctp_sndinfo sendv_sndinfo; 155 | #ifdef HAVE_SCTP_SENDV 156 | struct sctp_prinfo sendv_prinfo; 157 | struct sctp_authinfo sendv_authinfo; 158 | #endif 159 | }; 160 | 161 | #ifdef HAVE_SCTP_SENDV 162 | int sctp_sendv(int s, const struct iovec *iov, int iovcnt, 163 | struct sockaddr *addrs, int addrcnt, void *info, 164 | socklen_t infolen, unsigned int infotype, int flags); 165 | 166 | /* recvv infotype */ 167 | enum { 168 | SCTP_RECVV_NOINFO, 169 | SCTP_RECVV_RCVINFO, 170 | SCTP_RECVV_NXTINFO, 171 | SCTP_RECVV_RN 172 | }; 173 | 174 | struct sctp_recvv_rn { 175 | struct sctp_rcvinfo recvv_rcvinfo; 176 | struct sctp_nxtinfo recvv_nxtinfo; 177 | }; 178 | 179 | int sctp_recvv(int s, const struct iovec *iov, int iovlen, 180 | struct sockaddr *from, socklen_t *fromlen, void *info, 181 | socklen_t *infolen, unsigned int *infotype, int *flags); 182 | #endif 183 | 184 | #ifdef __cplusplus 185 | } 186 | #endif 187 | 188 | #endif /* __linux_sctp_h__ */ 189 | -------------------------------------------------------------------------------- /src/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | # Include these two in all the Makefile.am's!!! 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | include $(top_srcdir)/Makefile.dirs 5 | 6 | # General compilation flags 7 | AM_CPPFLAGS = -I$(top_builddir)/src/include 8 | 9 | lib_LTLIBRARIES = libsctp.la 10 | 11 | libsctp_la_SOURCES = bindx.c connectx.c peeloff.c opt_info.c \ 12 | addrs.c sendmsg.c recvmsg.c Versions.map 13 | libsctp_la_LDFLAGS = -version-info \ 14 | @LIBSCTP_CURRENT@:@LIBSCTP_REVISION@:@LIBSCTP_AGE@ \ 15 | -Wl,--version-script=$(srcdir)/Versions.map 16 | -------------------------------------------------------------------------------- /src/lib/Versions.map: -------------------------------------------------------------------------------- 1 | VERS_1 { 2 | global: 3 | sctp_getpaddrs; 4 | sctp_freepaddrs; 5 | sctp_getladdrs; 6 | sctp_freeladdrs; 7 | sctp_getaddrlen; 8 | sctp_bindx; 9 | sctp_connectx; 10 | sctp_opt_info; 11 | sctp_peeloff; 12 | sctp_recvmsg; 13 | sctp_recvv; 14 | sctp_sendmsg; 15 | sctp_sendv; 16 | sctp_send; 17 | 18 | local: 19 | *; 20 | }; 21 | 22 | VERS_2 { 23 | global: sctp_connectx; 24 | } VERS_1; 25 | 26 | VERS_3 { 27 | global: sctp_connectx; 28 | } VERS_2; 29 | -------------------------------------------------------------------------------- /src/lib/addrs.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * addrs.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 21 | * Sridhar Samudrala 22 | * Ivan Skytte Jørgensen 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /* 32 | * Common getsockopt() layer 33 | * If the NEW getsockopt() API fails this function will fall back to using 34 | * the old API 35 | */ 36 | static int 37 | sctp_getaddrs(int sd, sctp_assoc_t id, int optname_new, 38 | struct sockaddr **addrs) 39 | { 40 | int cnt, err; 41 | socklen_t len; 42 | size_t bufsize = 4096; /*enough for most cases*/ 43 | 44 | struct sctp_getaddrs *getaddrs = (struct sctp_getaddrs*)malloc(bufsize); 45 | if(!getaddrs) 46 | return -1; 47 | 48 | for(;;) { 49 | char *new_buf; 50 | 51 | len = bufsize; 52 | getaddrs->assoc_id = id; 53 | err = getsockopt(sd, SOL_SCTP, optname_new, getaddrs, &len); 54 | if (err == 0) { 55 | /*got it*/ 56 | break; 57 | } 58 | if (errno != ENOMEM ) { 59 | /*unknown error*/ 60 | free(getaddrs); 61 | return -1; 62 | } 63 | /*expand buffer*/ 64 | if (bufsize > 128*1024) { 65 | /*this is getting ridiculous*/ 66 | free(getaddrs); 67 | errno = ENOBUFS; 68 | return -1; 69 | } 70 | new_buf = realloc(getaddrs, bufsize+4096); 71 | if (!new_buf) { 72 | free(getaddrs); 73 | return -1; 74 | } 75 | bufsize += 4096; 76 | getaddrs = (struct sctp_getaddrs*)new_buf; 77 | } 78 | 79 | /* we skip traversing the list, allocating a new buffer etc. and enjoy 80 | * a simple hack*/ 81 | cnt = getaddrs->addr_num; 82 | memmove(getaddrs, getaddrs + 1, len); 83 | *addrs = (struct sockaddr*)getaddrs; 84 | 85 | return cnt; 86 | } /* sctp_getaddrs() */ 87 | 88 | /* Get all peer address on a socket. This is a new SCTP API 89 | * described in the section 8.3 of the Sockets API Extensions for SCTP. 90 | * This is implemented using the getsockopt() interface. 91 | */ 92 | int 93 | sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **addrs) 94 | { 95 | return sctp_getaddrs(sd, id, 96 | SCTP_GET_PEER_ADDRS, 97 | addrs); 98 | } /* sctp_getpaddrs() */ 99 | 100 | /* Frees all resources allocated by sctp_getpaddrs(). This is a new SCTP API 101 | * described in the section 8.4 of the Sockets API Extensions for SCTP. 102 | */ 103 | int 104 | sctp_freepaddrs(struct sockaddr *addrs) 105 | { 106 | free(addrs); 107 | return 0; 108 | 109 | } /* sctp_freepaddrs() */ 110 | 111 | /* Get all locally bound address on a socket. This is a new SCTP API 112 | * described in the section 8.5 of the Sockets API Extensions for SCTP. 113 | * This is implemented using the getsockopt() interface. 114 | */ 115 | int 116 | sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **addrs) 117 | { 118 | return sctp_getaddrs(sd, id, 119 | SCTP_GET_LOCAL_ADDRS, 120 | addrs); 121 | } /* sctp_getladdrs() */ 122 | 123 | /* Frees all resources allocated by sctp_getladdrs(). This is a new SCTP API 124 | * described in the section 8.6 of the Sockets API Extensions for SCTP. 125 | */ 126 | int 127 | sctp_freeladdrs(struct sockaddr *addrs) 128 | { 129 | free(addrs); 130 | return 0; 131 | 132 | } /* sctp_freeladdrs() */ 133 | 134 | int 135 | sctp_getaddrlen(sa_family_t family) 136 | { 137 | /* We could call into the kernel to see what it thinks the size should 138 | * be, but hardcoding the address families here is: (a) faster, 139 | * (b) easier, and (c) probably good enough for forseeable future. 140 | */ 141 | switch(family) { 142 | case AF_INET: 143 | return sizeof(struct sockaddr_in); 144 | case AF_INET6: 145 | return sizeof(struct sockaddr_in6); 146 | default: 147 | /* Currently there is no defined error handling in 148 | * draft-ietf-tsvwg-sctpsocket-13.txt. 149 | * -1 might cause the application to overwrite buffer 150 | * or misinterpret data. 0 is more likely to cause 151 | * an endless loop. 152 | */ 153 | return 0; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/lib/bindx.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * bindx.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 21 | * Daisy Chang 22 | * Inaky Perez-Gonzalez 23 | * Sridhar Samudrala 24 | */ 25 | 26 | #include /* struct sockaddr_storage, setsockopt() */ 27 | #include 28 | #include /* SCTP_SOCKOPT_BINDX_* */ 29 | #include 30 | 31 | /* Support the sctp_bindx() interface. 32 | * 33 | * See Sockets API Extensions for SCTP. Section 8.1. 34 | * 35 | * Instead of implementing through a socket call in sys_socketcall(), 36 | * tunnel the request through setsockopt(). 37 | */ 38 | int 39 | sctp_bindx(int fd, struct sockaddr *addrs, int addrcnt, int flags) 40 | { 41 | int setsock_option = 0; 42 | const char *addrbuf; 43 | struct sockaddr *sa_addr; 44 | socklen_t addrs_size = 0; 45 | int i; 46 | 47 | switch (flags) { 48 | case SCTP_BINDX_ADD_ADDR: 49 | setsock_option = SCTP_SOCKOPT_BINDX_ADD; 50 | break; 51 | case SCTP_BINDX_REM_ADDR: 52 | setsock_option = SCTP_SOCKOPT_BINDX_REM; 53 | break; 54 | default: 55 | errno = EINVAL; 56 | return -1; 57 | } 58 | 59 | addrbuf = (char*)addrs; 60 | for (i = 0; i < addrcnt; i++) { 61 | sa_addr = (struct sockaddr *)addrbuf; 62 | switch (sa_addr->sa_family) { 63 | case AF_INET: 64 | addrs_size += sizeof(struct sockaddr_in); 65 | addrbuf += sizeof(struct sockaddr_in); 66 | break; 67 | case AF_INET6: 68 | addrs_size += sizeof(struct sockaddr_in6); 69 | addrbuf += sizeof(struct sockaddr_in6); 70 | break; 71 | default: 72 | errno = EINVAL; 73 | return -1; 74 | } 75 | } 76 | 77 | return setsockopt(fd, SOL_SCTP, setsock_option, addrs, addrs_size); 78 | } 79 | -------------------------------------------------------------------------------- /src/lib/connectx.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * connectx.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt. 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 20 | */ 21 | 22 | #include /* struct sockaddr_storage, setsockopt() */ 23 | #include 24 | #include /* SCTP_SOCKOPT_CONNECTX_* */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "config.h" 30 | 31 | #define __SYMPFX(pfx, sym) #pfx sym 32 | #define _SYMPFX(pfx, sym) __SYMPFX(pfx, sym) 33 | #define SYMPFX(sym) _SYMPFX(__USER_LABEL_PREFIX__, #sym) 34 | 35 | #if HAVE_ATTRIBUTE_SYMVER 36 | #define SYMVER(name, name2) __attribute__ ((symver (SYMPFX(name2)))) 37 | #else 38 | #define SYMVER(name, name2) __asm__(".symver " SYMPFX(name) "," SYMPFX(name2)); 39 | #endif 40 | 41 | 42 | /* Support the sctp_connectx() interface. 43 | * 44 | * See Sockets API Extensions for SCTP. Section 8.1. 45 | * 46 | * Instead of implementing through a socket call in sys_socketcall(), 47 | * tunnel the request through setsockopt(). 48 | */ 49 | static int __connectx_addrsize(const struct sockaddr *addrs, 50 | const int addrcnt) 51 | { 52 | const char *addrbuf; 53 | const struct sockaddr *sa_addr; 54 | int addrs_size = 0; 55 | int i; 56 | 57 | addrbuf = (char *)addrs; 58 | for (i = 0; i < addrcnt; i++) { 59 | sa_addr = (const struct sockaddr *)addrbuf; 60 | switch (sa_addr->sa_family) { 61 | case AF_INET: 62 | addrs_size += sizeof(struct sockaddr_in); 63 | addrbuf += sizeof(struct sockaddr_in); 64 | break; 65 | case AF_INET6: 66 | addrs_size += sizeof(struct sockaddr_in6); 67 | addrbuf += sizeof(struct sockaddr_in6); 68 | break; 69 | default: 70 | errno = EINVAL; 71 | return -1; 72 | } 73 | } 74 | 75 | return addrs_size; 76 | } 77 | 78 | 79 | SYMVER(__sctp_connectx, sctp_connectx@) 80 | int __sctp_connectx(int fd, struct sockaddr *addrs, int addrcnt) 81 | { 82 | int addrs_size = __connectx_addrsize(addrs, addrcnt); 83 | 84 | if (addrs_size < 0) 85 | return addrs_size; 86 | 87 | return setsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_CONNECTX_OLD, addrs, 88 | addrs_size); 89 | } 90 | 91 | SYMVER(sctp_connectx_orig, sctp_connectx@VERS_1) 92 | extern int sctp_connectx_orig (int) 93 | __attribute ((alias ("__sctp_connectx"))); 94 | 95 | 96 | static int __connectx(int fd, struct sockaddr *addrs, socklen_t addrs_size, 97 | sctp_assoc_t *id) 98 | { 99 | int status; 100 | 101 | if (id) 102 | *id = 0; 103 | 104 | status = setsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_CONNECTX, addrs, 105 | addrs_size); 106 | 107 | /* Normalize status and set association id */ 108 | if (status > 0) { 109 | if (id) 110 | *id = status; 111 | return 0; 112 | } 113 | 114 | /* The error is something other then "Option not supported" */ 115 | if (status < 0 && errno != ENOPROTOOPT) 116 | return status; 117 | 118 | /* At this point, if the application wanted the id, we can't 119 | * really provide it, so we can return ENOPROTOOPT. 120 | */ 121 | if (id) { 122 | errno = ENOPROTOOPT; 123 | return -1; 124 | } 125 | 126 | /* Finally, try the old API */ 127 | return setsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_CONNECTX_OLD, 128 | addrs, addrs_size); 129 | } 130 | 131 | SYMVER(sctp_connectx2, sctp_connectx@VERS_2) 132 | int sctp_connectx2(int fd, struct sockaddr *addrs, int addrcnt, 133 | sctp_assoc_t *id) 134 | { 135 | int addrs_size = __connectx_addrsize(addrs, addrcnt); 136 | 137 | if (addrs_size < 0) 138 | return addrs_size; 139 | 140 | return __connectx(fd, addrs, addrs_size, id); 141 | } 142 | 143 | SYMVER(sctp_connectx3, sctp_connectx@@VERS_3) 144 | int sctp_connectx3(int fd, struct sockaddr *addrs, int addrcnt, 145 | sctp_assoc_t *id) 146 | { 147 | int addrs_size = __connectx_addrsize(addrs, addrcnt); 148 | int status; 149 | struct sctp_getaddrs_old param; 150 | socklen_t opt_len = sizeof(param); 151 | 152 | if (addrs_size < 0) 153 | return addrs_size; 154 | 155 | /* First try the new socket api 156 | * Because the id is returned in the option buffer we have prepend 157 | * 32bit to it for the returned association id 158 | */ 159 | param.assoc_id = 0; 160 | param.addr_num = addrs_size; 161 | param.addrs = addrs; 162 | status = getsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_CONNECTX3, 163 | ¶m, &opt_len); 164 | if (status == 0 || errno == EINPROGRESS) { 165 | /* Succeeded immediately, or initiated on non-blocking 166 | * socket. 167 | */ 168 | if (id) 169 | *id = param.assoc_id; 170 | } 171 | 172 | if (errno != ENOPROTOOPT) { 173 | /* No point in trying the fallbacks*/ 174 | return status; 175 | } 176 | 177 | /* The first incarnation of updated connectx api didn't work for 178 | * non-blocking sockets. So if the application wants the association 179 | * id and the socket is non-blocking, we can't really do anything. 180 | */ 181 | if (id) { 182 | /* Program wants the association-id returned. We can only do 183 | * that if the socket is blocking */ 184 | status = fcntl(fd, F_GETFL); 185 | if (status < 0) 186 | return status; 187 | 188 | if (status & O_NONBLOCK) { 189 | /* Socket is non-blocking. Fail */ 190 | errno = ENOPROTOOPT; 191 | return -1; 192 | } 193 | } 194 | 195 | return __connectx(fd, addrs, addrs_size, id); 196 | } 197 | 198 | -------------------------------------------------------------------------------- /src/lib/opt_info.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * opt_info.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code if to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 21 | */ 22 | 23 | #include /* struct sockaddr_storage, setsockopt() */ 24 | #include /* SCTP_SOCKOPT_BINDX_* */ 25 | #include 26 | 27 | /* Support the sctp_opt_info() interface. 28 | * 29 | * See Sockets API Extensions for SCTP. Section 7. 30 | * 31 | * Pass sctp option information pass both in to and out of the SCTP stack. 32 | * This is a new SCTP API described in the section 7 of the Sockets API 33 | * Extensions for SCTP. This is implemented using the getsockopt() interface. 34 | */ 35 | int 36 | sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t *size) 37 | { 38 | switch (opt) { 39 | case SCTP_RTOINFO: 40 | case SCTP_ASSOCINFO: 41 | case SCTP_INITMSG: 42 | case SCTP_NODELAY: 43 | case SCTP_AUTOCLOSE: 44 | case SCTP_PRIMARY_ADDR: 45 | case SCTP_DISABLE_FRAGMENTS: 46 | case SCTP_PEER_ADDR_PARAMS: 47 | case SCTP_DEFAULT_SEND_PARAM: 48 | case SCTP_EVENTS: 49 | case SCTP_I_WANT_MAPPED_V4_ADDR: 50 | case SCTP_MAXSEG: 51 | case SCTP_STATUS: 52 | case SCTP_GET_PEER_ADDR_INFO: 53 | case SCTP_AUTH_ACTIVE_KEY: 54 | case SCTP_PEER_AUTH_CHUNKS: 55 | case SCTP_LOCAL_AUTH_CHUNKS: 56 | *(sctp_assoc_t *)arg = id; 57 | return getsockopt(sd, IPPROTO_SCTP, opt, arg, size); 58 | default: 59 | return ENOTSUP; 60 | } 61 | 62 | } /* sctp_opt_info() */ 63 | -------------------------------------------------------------------------------- /src/lib/peeloff.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * peeloff.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 20 | */ 21 | 22 | #include /* struct sockaddr_storage, setsockopt() */ 23 | #include /* SCTP_SOCKOPT_BINDX_* */ 24 | #include 25 | 26 | #ifdef HAVE_SCTP_PEELOFF_FLAGS 27 | int 28 | sctp_peeloff_flags(int fd, sctp_assoc_t associd, unsigned flags) 29 | { 30 | socklen_t peeloff_size = sizeof(sctp_peeloff_flags_arg_t); 31 | sctp_peeloff_flags_arg_t peeloff; 32 | int err; 33 | 34 | if (!flags) 35 | return sctp_peeloff(fd, associd); 36 | 37 | peeloff.p_arg.associd = associd; 38 | peeloff.p_arg.sd = 0; 39 | peeloff.flags = flags; 40 | 41 | err = getsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_PEELOFF_FLAGS, &peeloff, 42 | &peeloff_size); 43 | 44 | if (err < 0) 45 | return err; 46 | 47 | return peeloff.p_arg.sd; 48 | } 49 | #endif 50 | 51 | /* Branch off an association into a seperate socket. This is a new SCTP API 52 | * described in the section 8.2 of the Sockets API Extensions for SCTP. 53 | * This is implemented using the getsockopt() interface. 54 | */ 55 | int 56 | sctp_peeloff(int fd, sctp_assoc_t associd) 57 | { 58 | socklen_t peeloff_size = sizeof(sctp_peeloff_arg_t); 59 | sctp_peeloff_arg_t peeloff; 60 | int err; 61 | 62 | peeloff.associd = associd; 63 | peeloff.sd = 0; 64 | 65 | err = getsockopt(fd, SOL_SCTP, SCTP_SOCKOPT_PEELOFF, &peeloff, 66 | &peeloff_size); 67 | 68 | if (err < 0) 69 | return err; 70 | 71 | return peeloff.sd; 72 | } 73 | -------------------------------------------------------------------------------- /src/lib/recvmsg.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * sctp_recvmsg.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 15 | * 16 | * Copyright (c) 2003 International Business Machines, Corp. 17 | * 18 | * Written or modified by: 19 | * Ryan Layer 20 | * 21 | * An implementation may provide a library function (or possibly system 22 | * call) to assist the user with the advanced features of SCTP. Note 23 | * that in order for the sctp_sndrcvinfo structure to be filled in by 24 | * sctp_recvmsg() the caller must enable the sctp_data_io_events with 25 | * the SCTP_EVENTS option. 26 | * 27 | * sctp_recvmsg(). Its syntax is, 28 | * 29 | * int sctp_recvmsg(int s, 30 | * void *msg, 31 | * size_t len, 32 | * struct sockaddr *from, 33 | * socklen_t *fromlen, 34 | * struct sctp_sndrcvinfo *sinfo, 35 | * int *msg_flags) 36 | * 37 | * 38 | * s - is the socket descriptor 39 | * msg - is a message buffer to be filled. 40 | * len - is the length of the message buffer. 41 | * from - is a pointer to a address to be filled with 42 | * the sender of this messages address. 43 | * fromlen - is the from length. 44 | * sinfo - A pointer to a sctp_sndrcvinfo structure 45 | * to be filled upon receipt of the message. 46 | * msg_flags - A pointer to a integer to be filled with 47 | * any message flags (e.g. MSG_NOTIFICATION). 48 | */ 49 | 50 | #include 51 | #include 52 | #include /* struct sockaddr_storage, setsockopt() */ 53 | #include 54 | 55 | int sctp_recvmsg(int s, void *msg, size_t len, struct sockaddr *from, 56 | socklen_t *fromlen, struct sctp_sndrcvinfo *sinfo, 57 | int *msg_flags) 58 | { 59 | int error; 60 | struct iovec iov; 61 | struct msghdr inmsg; 62 | char incmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; 63 | struct cmsghdr *cmsg = NULL; 64 | 65 | memset(&inmsg, 0, sizeof (inmsg)); 66 | 67 | iov.iov_base = msg; 68 | iov.iov_len = len; 69 | 70 | inmsg.msg_name = from; 71 | inmsg.msg_namelen = fromlen ? *fromlen : 0; 72 | inmsg.msg_iov = &iov; 73 | inmsg.msg_iovlen = 1; 74 | inmsg.msg_control = incmsg; 75 | inmsg.msg_controllen = sizeof(incmsg); 76 | 77 | error = recvmsg(s, &inmsg, msg_flags ? *msg_flags : 0); 78 | if (error < 0) 79 | return error; 80 | 81 | if (fromlen) 82 | *fromlen = inmsg.msg_namelen; 83 | if (msg_flags) 84 | *msg_flags = inmsg.msg_flags; 85 | 86 | if (!sinfo) 87 | return error; 88 | 89 | /* zero-initialize sctp_assoc_id, as the kernel always uses sctp_assoc_id > 0 90 | * and hence the caller can check for sinfo_assoc_id != 0 to determine if the kernel 91 | * actually provided a SCPT_SNDRCV cmsg below. */ 92 | sinfo->sinfo_assoc_id = 0; 93 | 94 | for (cmsg = CMSG_FIRSTHDR(&inmsg); cmsg != NULL; 95 | cmsg = CMSG_NXTHDR(&inmsg, cmsg)){ 96 | if ((IPPROTO_SCTP == cmsg->cmsg_level) && 97 | (SCTP_SNDRCV == cmsg->cmsg_type)) 98 | break; 99 | } 100 | 101 | /* Copy sinfo. */ 102 | if (cmsg) 103 | memcpy(sinfo, CMSG_DATA(cmsg), sizeof(struct sctp_sndrcvinfo)); 104 | 105 | return (error); 106 | } 107 | 108 | #ifdef HAVE_SCTP_SENDV 109 | int sctp_recvv(int s, const struct iovec *iov, int iovlen, 110 | struct sockaddr *from, socklen_t *fromlen, void *info, 111 | socklen_t *infolen, unsigned int *infotype, int *flags) 112 | { 113 | char incmsg[CMSG_SPACE(sizeof(struct sctp_rcvinfo)) + 114 | CMSG_SPACE(sizeof(struct sctp_nxtinfo))]; 115 | int error, len, _infolen; 116 | struct cmsghdr *cmsg; 117 | struct msghdr inmsg; 118 | 119 | memset(&inmsg, 0, sizeof(inmsg)); 120 | 121 | /* set from and iov */ 122 | inmsg.msg_name = from; 123 | inmsg.msg_namelen = fromlen ? *fromlen : 0; 124 | inmsg.msg_iov = (struct iovec *)iov; 125 | inmsg.msg_iovlen = iovlen; 126 | inmsg.msg_control = incmsg; 127 | inmsg.msg_controllen = sizeof(incmsg); 128 | 129 | error = recvmsg(s, &inmsg, flags ? *flags : 0); 130 | if (error < 0) 131 | return error; 132 | 133 | /* set fromlen, frags */ 134 | if (fromlen) 135 | *fromlen = inmsg.msg_namelen; 136 | 137 | if (flags) 138 | *flags = inmsg.msg_flags; 139 | 140 | if (!info || !infotype || !infolen) 141 | return error; 142 | 143 | *infotype = SCTP_RECVV_NOINFO; 144 | _infolen = *infolen; 145 | 146 | /* set info and infotype */ 147 | for (cmsg = CMSG_FIRSTHDR(&inmsg); cmsg != NULL; 148 | cmsg = CMSG_NXTHDR(&inmsg, cmsg)) { 149 | if (cmsg->cmsg_level != IPPROTO_SCTP) 150 | continue; 151 | 152 | if (cmsg->cmsg_type == SCTP_RCVINFO) { 153 | len = sizeof(struct sctp_rcvinfo); 154 | if (*infotype == SCTP_RECVV_NOINFO) { 155 | if (_infolen < len) 156 | break; 157 | memcpy(info, CMSG_DATA(cmsg), len); 158 | *infotype = SCTP_RECVV_RCVINFO; 159 | *infolen = len; 160 | } else if (*infotype == SCTP_RECVV_NXTINFO) { 161 | if (_infolen < len + 162 | sizeof(struct sctp_nxtinfo)) 163 | break; 164 | memcpy(info + len, info, 165 | sizeof(struct sctp_nxtinfo)); 166 | memcpy(info, CMSG_DATA(cmsg), len); 167 | *infotype = SCTP_RECVV_RN; 168 | *infolen = len + sizeof(struct sctp_nxtinfo); 169 | } else { 170 | break; 171 | } 172 | } else if (cmsg->cmsg_type == SCTP_NXTINFO) { 173 | len = sizeof(struct sctp_nxtinfo); 174 | if (*infotype == SCTP_RECVV_NOINFO) { 175 | if (_infolen < len) 176 | break; 177 | memcpy(info, CMSG_DATA(cmsg), len); 178 | *infotype = SCTP_RECVV_NXTINFO; 179 | *infolen = len; 180 | } else if (*infotype == SCTP_RECVV_RCVINFO) { 181 | if (_infolen < len + 182 | sizeof(struct sctp_rcvinfo)) 183 | break; 184 | memcpy(info + sizeof(struct sctp_rcvinfo), 185 | CMSG_DATA(cmsg), len); 186 | *infotype = SCTP_RECVV_RN; 187 | *infolen = len + sizeof(struct sctp_rcvinfo); 188 | } else { 189 | break; 190 | } 191 | } 192 | } 193 | 194 | return error; 195 | } 196 | #endif 197 | -------------------------------------------------------------------------------- /src/lib/sendmsg.c: -------------------------------------------------------------------------------- 1 | /* SCTP kernel Implementation: User API extensions. 2 | * 3 | * sendmsg.c 4 | * 5 | * Distributed under the terms of the LGPL v2.1 as described in 6 | * http://www.gnu.org/copyleft/lesser.txt 7 | * 8 | * This file is part of the user library that offers support for the 9 | * SCTP kernel Implementation. The main purpose of this 10 | * code is to provide the SCTP Socket API mappings for user 11 | * application to interface with the SCTP in kernel. 12 | * 13 | * This implementation is based on the Socket API Extensions for SCTP 14 | * defined in 15 | * 16 | * Copyright (c) 2003 Intel Corp. 17 | * 18 | * Written or modified by: 19 | * Ardelle Fan 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include /* struct sockaddr_storage, setsockopt() */ 27 | #include 28 | 29 | /* This library function assists the user with the advanced features 30 | * of SCTP. This is a new SCTP API described in the section 8.7 of the 31 | * Sockets API Extensions for SCTP. This is implemented using the 32 | * sendmsg() interface. 33 | */ 34 | int 35 | sctp_sendmsg(int s, const void *msg, size_t len, struct sockaddr *to, 36 | socklen_t tolen, uint32_t ppid, uint32_t flags, 37 | uint16_t stream_no, uint32_t timetolive, uint32_t context) 38 | { 39 | struct msghdr outmsg; 40 | struct iovec iov; 41 | char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; 42 | struct cmsghdr *cmsg; 43 | struct sctp_sndrcvinfo *sinfo; 44 | 45 | outmsg.msg_name = to; 46 | outmsg.msg_namelen = tolen; 47 | outmsg.msg_iov = &iov; 48 | iov.iov_base = (void *)msg; 49 | iov.iov_len = len; 50 | outmsg.msg_iovlen = 1; 51 | 52 | outmsg.msg_control = outcmsg; 53 | outmsg.msg_controllen = sizeof(outcmsg); 54 | outmsg.msg_flags = 0; 55 | 56 | cmsg = CMSG_FIRSTHDR(&outmsg); 57 | cmsg->cmsg_level = IPPROTO_SCTP; 58 | cmsg->cmsg_type = SCTP_SNDRCV; 59 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 60 | 61 | outmsg.msg_controllen = cmsg->cmsg_len; 62 | sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); 63 | memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo)); 64 | sinfo->sinfo_ppid = ppid; 65 | sinfo->sinfo_flags = flags; 66 | sinfo->sinfo_stream = stream_no; 67 | sinfo->sinfo_timetolive = timetolive; 68 | sinfo->sinfo_context = context; 69 | 70 | return sendmsg(s, &outmsg, 0); 71 | } 72 | 73 | /* This library function assist the user with sending a message without 74 | * dealing directly with the CMSG header. 75 | */ 76 | int 77 | sctp_send(int s, const void *msg, size_t len, 78 | const struct sctp_sndrcvinfo *sinfo, int flags) 79 | { 80 | struct msghdr outmsg = {}; 81 | struct iovec iov; 82 | char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; 83 | 84 | outmsg.msg_iov = &iov; 85 | iov.iov_base = (void *)msg; 86 | iov.iov_len = len; 87 | outmsg.msg_iovlen = 1; 88 | outmsg.msg_flags = flags; 89 | 90 | if (sinfo) { 91 | struct cmsghdr *cmsg; 92 | 93 | outmsg.msg_control = outcmsg; 94 | outmsg.msg_controllen = sizeof(outcmsg); 95 | 96 | cmsg = CMSG_FIRSTHDR(&outmsg); 97 | cmsg->cmsg_level = IPPROTO_SCTP; 98 | cmsg->cmsg_type = SCTP_SNDRCV; 99 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); 100 | 101 | outmsg.msg_controllen = cmsg->cmsg_len; 102 | memcpy(CMSG_DATA(cmsg), sinfo, sizeof(struct sctp_sndrcvinfo)); 103 | } 104 | 105 | return sendmsg(s, &outmsg, flags); 106 | } 107 | 108 | #ifdef HAVE_SCTP_SENDV 109 | static struct cmsghdr *sctp_sendv_store_cmsg(struct cmsghdr *cmsg, int *cmsglen, 110 | int type, int len, void *data) 111 | { 112 | cmsg->cmsg_level = IPPROTO_SCTP; 113 | cmsg->cmsg_type = type; 114 | cmsg->cmsg_len = CMSG_LEN(len); 115 | memcpy(CMSG_DATA(cmsg), data, len); 116 | 117 | *cmsglen += CMSG_SPACE(len); 118 | 119 | return (struct cmsghdr *)((char *)cmsg + CMSG_SPACE(len)); 120 | } 121 | 122 | int sctp_sendv(int s, const struct iovec *iov, int iovcnt, 123 | struct sockaddr *addrs, int addrcnt, void *info, 124 | socklen_t infolen, unsigned int infotype, int flags) 125 | { 126 | char _cmsg[CMSG_SPACE(sizeof(struct sctp_sndinfo)) + 127 | CMSG_SPACE(sizeof(struct sctp_prinfo)) + 128 | CMSG_SPACE(sizeof(struct sctp_authinfo))]; 129 | struct cmsghdr *cmsg = (struct cmsghdr *)_cmsg; 130 | struct msghdr outmsg = {}; 131 | struct sockaddr *addr; 132 | int len, cmsglen = 0; 133 | int err, type, i; 134 | char *addrbuf; 135 | 136 | outmsg.msg_iov = (struct iovec *)iov; 137 | outmsg.msg_iovlen = iovcnt; 138 | outmsg.msg_flags = flags; 139 | 140 | /* set msg_name and msg_namelen */ 141 | if (addrs && addrcnt) { 142 | outmsg.msg_name = addrs; 143 | if (addrs->sa_family == AF_INET) 144 | outmsg.msg_namelen = sizeof(struct sockaddr_in); 145 | else if (addrs->sa_family == AF_INET6) 146 | outmsg.msg_namelen = sizeof(struct sockaddr_in6); 147 | else 148 | return -EINVAL; 149 | addrcnt -= 1; 150 | addrbuf = (char *)addrs; 151 | addrs = (struct sockaddr *)(addrbuf + outmsg.msg_namelen); 152 | } 153 | 154 | /* alloc memory only when it's multi-address */ 155 | if (addrcnt) { 156 | len = CMSG_SPACE(sizeof(struct sockaddr_in6)) * addrcnt; 157 | cmsg = malloc(sizeof(_cmsg) + len); 158 | if (!cmsg) 159 | return -ENOMEM; 160 | } 161 | 162 | outmsg.msg_control = cmsg; 163 | 164 | /* add cmsg info for addr info */ 165 | for (i = 0, addrbuf = (char *)addrs; i < addrcnt; i++) { 166 | void *ainfo; 167 | 168 | addr = (struct sockaddr *)addrbuf; 169 | if (addr->sa_family == AF_INET) { 170 | struct sockaddr_in *a = (struct sockaddr_in *)addrbuf; 171 | 172 | len = sizeof(struct in_addr); 173 | type = SCTP_DSTADDRV4; 174 | ainfo = &a->sin_addr; 175 | addrbuf += sizeof(*a); 176 | } else if (addr->sa_family == AF_INET6) { 177 | struct sockaddr_in6 *a = (struct sockaddr_in6 *)addrbuf; 178 | 179 | len = sizeof(struct in6_addr); 180 | type = SCTP_DSTADDRV6; 181 | ainfo = &a->sin6_addr; 182 | addrbuf += sizeof(*a); 183 | } else { 184 | free(outmsg.msg_control); 185 | return -EINVAL; 186 | } 187 | 188 | cmsg = sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, ainfo); 189 | } 190 | /* add cmsg info for addr info for snd/pr/auth info */ 191 | if (infotype == SCTP_SENDV_SPA) { 192 | struct sctp_sendv_spa *spa = info; 193 | 194 | if (spa->sendv_flags & SCTP_SEND_SNDINFO_VALID) { 195 | type = SCTP_SNDINFO; 196 | len = sizeof(struct sctp_sndinfo); 197 | cmsg = sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, 198 | &spa->sendv_sndinfo); 199 | } 200 | if (spa->sendv_flags & SCTP_SEND_PRINFO_VALID) { 201 | type = SCTP_PRINFO; 202 | len = sizeof(struct sctp_prinfo); 203 | cmsg = sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, 204 | &spa->sendv_prinfo); 205 | } 206 | if (spa->sendv_flags & SCTP_SEND_AUTHINFO_VALID) { 207 | type = SCTP_AUTHINFO; 208 | len = sizeof(struct sctp_authinfo); 209 | sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, 210 | &spa->sendv_authinfo); 211 | } 212 | } else if (infotype == SCTP_SENDV_SNDINFO) { 213 | type = SCTP_SNDINFO; 214 | len = sizeof(struct sctp_sndinfo); 215 | sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, info); 216 | } else if (infotype == SCTP_SENDV_PRINFO) { 217 | type = SCTP_PRINFO; 218 | len = sizeof(struct sctp_prinfo); 219 | sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, info); 220 | } else if (infotype == SCTP_SENDV_AUTHINFO) { 221 | type = SCTP_AUTHINFO; 222 | len = sizeof(struct sctp_authinfo); 223 | sctp_sendv_store_cmsg(cmsg, &cmsglen, type, len, info); 224 | } 225 | 226 | outmsg.msg_controllen = cmsglen; 227 | 228 | err = sendmsg(s, &outmsg, 0); 229 | 230 | if (outmsg.msg_control != _cmsg) 231 | free(outmsg.msg_control); 232 | 233 | return err; 234 | } 235 | #endif 236 | -------------------------------------------------------------------------------- /src/testlib/Makefile.am: -------------------------------------------------------------------------------- 1 | # Include these two in all the Makefile.am's!!! 2 | include $(top_srcdir)/Makefile.vars 3 | include $(top_srcdir)/Makefile.rules 4 | 5 | include $(top_srcdir)/Makefile.dirs 6 | 7 | # General compilation flags 8 | AM_CPPFLAGS = -I$(top_builddir)/src/include 9 | 10 | noinst_LTLIBRARIES = libsctputil.la 11 | libsctputil_la_SOURCES = sctputil.c sctputil.h 12 | libsctputil_la_LDFLAGS = 13 | -------------------------------------------------------------------------------- /src/withsctp/.gitignore: -------------------------------------------------------------------------------- 1 | checksctp 2 | withsctp 3 | -------------------------------------------------------------------------------- /src/withsctp/Makefile.am: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # The author (La Monte H.P. Yarroll) disclaims copyright on this file. 4 | # 5 | 6 | include $(top_srcdir)/Makefile.vars 7 | include $(top_srcdir)/Makefile.dirs 8 | include $(top_srcdir)/Makefile.rules 9 | 10 | bin_PROGRAMS = checksctp 11 | bin_SCRIPTS = withsctp 12 | 13 | AM_CPPFLAGS=-I$(top_builddir)/src/include 14 | pkglib_LTLIBRARIES = libwithsctp.la 15 | libwithsctp_la_SOURCES = sctp_load_libs.c sctp_socket.c sctp_bind.c \ 16 | sctp_sockopt.c sctp_socket.h 17 | libwithsctp_la_LDFLAGS = -version-info \ 18 | @LIBWITHSCTP_CURRENT@:@LIBWITHSCTP_REVISION@:@LIBWITHSCTP_AGE@ -ldl 19 | 20 | pkgdoc_DATA = sctp_load_libs.c sctp_socket.c sctp_bind.c \ 21 | sctp_sockopt.c sctp_socket.h checksctp.c 22 | 23 | withsctp: withsctp.in 24 | $(edit) $< >$@ 25 | 26 | EXTRA_DIST += withsctp.in 27 | 28 | CLEANFILES += withsctp 29 | -------------------------------------------------------------------------------- /src/withsctp/README: -------------------------------------------------------------------------------- 1 | This is a package to let you use SCTP with your existing TCP-based binaries. 2 | 3 | usage: 4 | 5 | $ withsctp xinetd # Start xinetd stream services on SCTP. 6 | $ withsctp telnet localhost # Make a telnet over SCTP/IP connection. 7 | 8 | To install, edit the top of Makefile to set your install path(s) and then 9 | 10 | $ make all 11 | # make install 12 | 13 | This package originally written by La Monte H.P. Yarroll . 14 | To submit fixes or bug reports see https://github.com/sctp/lksctp-tools/ 15 | You can try linux-sctp@vger.kernel.org for support. 16 | -------------------------------------------------------------------------------- /src/withsctp/checksctp.c: -------------------------------------------------------------------------------- 1 | /* Does this host have SCTP? 2 | * 3 | * Copyright 2003 La Monte HP Yarroll 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following 13 | * disclaimer in the documentation and/or other materials provided with 14 | * the distribution. 15 | * 3. The name of the author may not be used to endorse or promote 16 | * products derived from this software without specific prior written 17 | * permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | /* IPPROTO_SCTP SHOULD be defined in 38 | * /usr/include/linux/in.h but probably isn't. 39 | * It is an enum element, not a #define, so we can't easily check. 40 | */ 41 | #define SHOULD_IPPROTO_SCTP 132 42 | 43 | int main(void) 44 | { 45 | int fd; 46 | 47 | fd = socket(PF_INET, SOCK_STREAM, SHOULD_IPPROTO_SCTP); 48 | 49 | if (fd <= 0) { 50 | perror("checksctp"); 51 | exit(1); 52 | } else { 53 | fprintf(stderr, "SCTP supported\n"); 54 | } 55 | 56 | close(fd); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/withsctp/notes.txt: -------------------------------------------------------------------------------- 1 | Fri Dec 26 16:20:36 EST 2003 2 | 3 | It would be nice for withsctp to provide more facilities. 4 | 5 | Perhaps we could capture the bind call and allow substitution such as the 6 | arguments to sctp_darn. 7 | -------------------------------------------------------------------------------- /src/withsctp/sctp_bind.c: -------------------------------------------------------------------------------- 1 | /* Wrap bind() to force the protocol for STREAM connections to SCTP. 2 | * 3 | * Thanks to Midgard Security Services for 4 | * http://www.securiteam.com/tools/3D5PTR5QAE.html 5 | * from whence I cribbed the code to find the old bind(). 6 | * 7 | * gcc sctp_socket.c sctp_bind.c -o sctp_socket.so -ldl -shared -O2 -s 8 | * export LD_PRELOAD=./sctp_socket.so 9 | * 10 | * Copyright 2003 La Monte HP Yarroll 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above 19 | * copyright notice, this list of conditions and the following 20 | * disclaimer in the documentation and/or other materials provided with 21 | * the distribution. 22 | * 3. The name of the author may not be used to endorse or promote 23 | * products derived from this software without specific prior written 24 | * permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 32 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 34 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 35 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 36 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | #include /* for strncmp() */ 39 | #include 40 | #include "sctp_socket.h" 41 | 42 | /* IPPROTO_SCTP SHOULD be defined in 43 | * /usr/include/linux/in.h but probably isn't. 44 | * It is an enum element, not a #define, so we can't easily check. 45 | */ 46 | #define SHOULD_IPPROTO_SCTP 132 47 | 48 | int 49 | bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen) 50 | { 51 | _sctp_load_libs(); 52 | 53 | /* STUB. The intent is to allow us to substitute an elaborate call to 54 | * bindx() for the initial call to bind(). TBD. 55 | */ 56 | 57 | return (real_bind)(sockfd, my_addr, addrlen); 58 | } 59 | -------------------------------------------------------------------------------- /src/withsctp/sctp_load_libs.c: -------------------------------------------------------------------------------- 1 | /* Load the real underlying functions for withsctp and related scripts. 2 | * 3 | * Copyright 2003 La Monte HP Yarroll 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following 13 | * disclaimer in the documentation and/or other materials provided with 14 | * the distribution. 15 | * 3. The name of the author may not be used to endorse or promote 16 | * products derived from this software without specific prior written 17 | * permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include 32 | #include 33 | #include "sctp_socket.h" 34 | 35 | int (*real_bind)(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); 36 | int (*real_socket)(int domain, int type, int protocol); 37 | int (*real_setsockopt)(int s, int level, int optname, const void *optval, 38 | socklen_t optlen); 39 | static void *lib_handle = NULL; 40 | 41 | void 42 | _sctp_load_libs(void) 43 | { 44 | if (NULL != lib_handle) return; /* Only init once. */ 45 | 46 | if (!(lib_handle = dlopen("libc.so", RTLD_LAZY))) { 47 | if (!(lib_handle = dlopen("libc.so.6", RTLD_LAZY))) { 48 | fprintf(stderr, "error loading libc!\n"); 49 | exit (1); 50 | } 51 | } 52 | 53 | if (!(real_socket = dlsym(lib_handle, "socket"))) { 54 | fprintf(stderr, "socket() not found in libc!\n"); 55 | exit (1); 56 | } 57 | 58 | if (!(real_bind = dlsym(lib_handle, "bind"))) { 59 | fprintf(stderr, "bind() not found in libc!\n"); 60 | exit (1); 61 | } 62 | 63 | if (!(real_setsockopt = dlsym(lib_handle, "setsockopt"))) { 64 | fprintf(stderr, "setsockopt() not found in libc!\n"); 65 | exit (1); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/withsctp/sctp_socket.c: -------------------------------------------------------------------------------- 1 | /* Wrap socket() to force the protocol to SCTP for STREAM connections. 2 | * 3 | * Thanks to Midgard Security Services for 4 | * http://www.securiteam.com/tools/3D5PTR5QAE.html 5 | * from whence I cribbed the code to find the old socket(). 6 | * 7 | * gcc sctp_socket.c -o sctp_socket.so -ldl -shared -O2 -s 8 | * export LD_PRELOAD=./sctp_socket.so 9 | * 10 | * Copyright 2003 La Monte HP Yarroll 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above 19 | * copyright notice, this list of conditions and the following 20 | * disclaimer in the documentation and/or other materials provided with 21 | * the distribution. 22 | * 3. The name of the author may not be used to endorse or promote 23 | * products derived from this software without specific prior written 24 | * permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 32 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 34 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 35 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 36 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | #include /* for strncmp() */ 39 | #include 40 | #include "sctp_socket.h" 41 | 42 | /* IPPROTO_SCTP SHOULD be defined in 43 | * /usr/include/linux/in.h but probably isn't. 44 | * It is an enum element, not a #define, so we can't easily check. 45 | */ 46 | #define SHOULD_IPPROTO_SCTP 132 47 | 48 | int 49 | socket(int domain, int type, int protocol) 50 | { 51 | _sctp_load_libs(); 52 | 53 | if (((PF_INET == domain) || (PF_INET6 == domain)) 54 | && (SOCK_STREAM == type)) { 55 | protocol = SHOULD_IPPROTO_SCTP; 56 | } 57 | 58 | return (real_socket)(domain, type, protocol); 59 | } 60 | -------------------------------------------------------------------------------- /src/withsctp/sctp_socket.h: -------------------------------------------------------------------------------- 1 | /* Preprocessor definitions for withsctp and supporting scripts. 2 | * 3 | * Copyright 2003 La Monte HP Yarroll 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following 13 | * disclaimer in the documentation and/or other materials provided with 14 | * the distribution. 15 | * 3. The name of the author may not be used to endorse or promote 16 | * products derived from this software without specific prior written 17 | * permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * Copyright 2003 La Monte HP Yarroll 31 | * 32 | * Redistribution and use in source and binary forms, with or without 33 | * modification, are permitted provided that the following conditions 34 | * are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright 37 | * notice, this list of conditions and the following disclaimer. 38 | * 2. Redistributions in binary form must reproduce the above 39 | * copyright notice, this list of conditions and the following 40 | * disclaimer in the documentation and/or other materials provided with 41 | * the distribution. 42 | * 3. The name of the author may not be used to endorse or promote 43 | * products derived from this software without specific prior written 44 | * permission. 45 | * 46 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 47 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 48 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 49 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 50 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 52 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 53 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 54 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 55 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 56 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | */ 58 | #include /* for dlopen() and company */ 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | extern int (*real_bind)(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); 66 | extern int (*real_socket)(int domain, int type, int protocol); 67 | extern int (*real_setsockopt)(int s, int level, int optname, const void *optval, 68 | socklen_t optlen); 69 | extern void _sctp_load_libs(void); 70 | -------------------------------------------------------------------------------- /src/withsctp/sctp_sockopt.c: -------------------------------------------------------------------------------- 1 | /* Wrap socket() to force the protocol to SCTP for STREAM connections. 2 | * 3 | * Thanks to Midgard Security Services for 4 | * http://www.securiteam.com/tools/3D5PTR5QAE.html 5 | * from whence I cribbed the code to find the old socket(). 6 | * 7 | * Copyright 2003 La Monte HP Yarroll 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above 16 | * copyright notice, this list of conditions and the following 17 | * disclaimer in the documentation and/or other materials provided with 18 | * the distribution. 19 | * 3. The name of the author may not be used to endorse or promote 20 | * products derived from this software without specific prior written 21 | * permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 29 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 31 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 33 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | #include /* for strncmp() */ 36 | #include 37 | #include "sctp_socket.h" 38 | 39 | /* IPPROTO_SCTP SHOULD be defined in 40 | * /usr/include/linux/in.h but probably isn't. 41 | * It is an enum element, not a #define, so we can't easily check. 42 | */ 43 | #define SHOULD_IPPROTO_SCTP 132 44 | 45 | int 46 | setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) 47 | { 48 | _sctp_load_libs(); 49 | 50 | if ((IPPROTO_TCP == level) && (TCP_NODELAY == optname)) { 51 | level = SHOULD_IPPROTO_SCTP; 52 | optname = SCTP_NODELAY; 53 | } 54 | 55 | return (real_setsockopt)(s, level, optname, optval, optlen); 56 | } 57 | -------------------------------------------------------------------------------- /src/withsctp/withsctp.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- sh -*- 3 | LIBDIR=@libdir@/@PACKAGE@ 4 | BINDIR=@bindir@ 5 | LIBVER=@LIBWITHSCTP_CURRENT@.@LIBWITHSCTP_AGE@.@LIBWITHSCTP_REVISION@ 6 | export LD_PRELOAD=${LIBDIR}/libwithsctp.so.${LIBVER} 7 | if ! ${BINDIR}/checksctp 2> /dev/null 8 | then 9 | ${BINDIR}/checksctp; 10 | exit 1; 11 | fi 12 | 13 | exec "$@" 14 | -------------------------------------------------------------------------------- /stamp-h.in: -------------------------------------------------------------------------------- 1 | timestamp 2 | --------------------------------------------------------------------------------