diff --git a/.gitignore b/.gitignore index a6caa91e..093289c9 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ tests/test-commands tests/test-configuration tests/test-cxx-build tests/test-id-manager +tests/mptcpwrap-tester tests/*.log tests/*.trs tests/test-suite.log diff --git a/src/mptcpwrap.c b/src/mptcpwrap.c index 1aaf00f2..c445a9a0 100644 --- a/src/mptcpwrap.c +++ b/src/mptcpwrap.c @@ -26,7 +26,7 @@ int __attribute__((visibility("default"))) socket(int family, int type, int prot (type & 0xff) != SOCK_STREAM) goto do_socket; - // socket(AF_INET, SOCK_STREM, 0) maps to TCP, too + // socket(AF_INET, SOCK_STREAM, 0) maps to TCP, too if (protocol != 0 && protocol != IPPROTO_TCP) goto do_socket; diff --git a/tests/Makefile.am b/tests/Makefile.am index d1623459..c2f9942c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,6 +28,8 @@ check_PROGRAMS = \ test-configuration \ test-id-manager +noinst_PROGRAMS = mptcpwrap-tester + dist_check_SCRIPTS = \ test-bad-log-empty \ test-bad-log-long \ @@ -35,7 +37,8 @@ dist_check_SCRIPTS = \ test-bad-option \ test-bad-path-manager \ test-bad-plugin-dir \ - test-start-stop + test-start-stop \ + test-mptcpwrap test_plugin_SOURCES = test-plugin.c test_plugin_CPPFLAGS = \ @@ -94,6 +97,9 @@ test_id_manager_LDADD = \ $(ELL_LIBS) \ $(CODE_COVERAGE_LIBS) +mptcpwrap_tester_SOURCES = mptcpwrap-tester.c +mptcpwrap_tester_LDADD = $(CODE_COVERAGE_LIBS) + if HAVE_CXX check_PROGRAMS += test-cxx-build test_cxx_build_SOURCES = test-cxx-build.cpp diff --git a/tests/mptcpwrap-tester.c b/tests/mptcpwrap-tester.c new file mode 100644 index 00000000..7d01c1ed --- /dev/null +++ b/tests/mptcpwrap-tester.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: BSD-3-Clause +/** + * @file mptcpwrap-tester.c + * + * @brief Test wrapped socket() call for MPTCP protocol injection. + * + * Copyright (c) 2021, Intel Corporation + */ + +#undef NDEBUG +#include + +#include +#include +#include +#include + +int main() +{ + /* + libmptcpwrap.so should be preloaded when running this + program, e.g.: + + LD_PRELOAD=libmptcpwrap.so ./mptcpwrap-tester + */ + int const fd = socket(AF_INET, SOCK_STREAM, 0); + assert(fd != -1); + + int protocol = 0; + socklen_t len = sizeof(protocol); + + int const expected_protocol = IPPROTO_TCP + 256; // MPTCP-ized. + + int const ret = getsockopt(fd, + SOL_SOCKET, + SO_PROTOCOL, + &protocol, + &len); + + close(fd); + + assert(ret == 0 + && protocol == expected_protocol + && len == sizeof(protocol)); + + return 0; +} + + +/* + Local Variables: + c-file-style: "linux" + End: +*/ diff --git a/tests/test-mptcpwrap b/tests/test-mptcpwrap new file mode 100755 index 00000000..8d12f432 --- /dev/null +++ b/tests/test-mptcpwrap @@ -0,0 +1,10 @@ +#! /bin/sh +# SPDX-License-Identifier: BSD-3-Clause + +# Test that libmptcpwrap injects MPTCP into the socket() system call. +# +# Copyright (c) 2021, Intel Corporation + +set -e + +LD_PRELOAD=../src/.libs/libmptcpwrap.so ./mptcpwrap-tester