Hi Paolo,
On 08/10/2019 22:21, Paolo Abeni wrote:
On Tue, 2019-10-08 at 17:00 +0200, Matthieu Baerts wrote:
> Hi Davide,
>
> On 08/10/2019 16:43, Davide Caratti wrote:
>> add a selftest to verify that the kernel forbids attaching MPTCP subflows
>> to userspace TCP sockets with setsockopt(..., IPPROTO_TCP, TCP_ULP, ...).
>
> Good idea to have a test for that!
>
>> Signed-off-by: Davide Caratti <dcaratti(a)redhat.com>
>> ---
>> .../selftests/net/mptcp/mptcp_connect.c | 49 +++++++++++++++++--
>> .../selftests/net/mptcp/mptcp_connect.sh | 19 +++++++
>> 2 files changed, 65 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c
b/tools/testing/selftests/net/mptcp/mptcp_connect.c
>> index cac71f0ac8f8..12a722e0c527 100644
>> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
>> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
>
> [...]
>
>> @@ -114,6 +116,41 @@ static int sock_listen_mptcp(const char * const listenaddr,
>> return sock;
>> }
>>
>> +static bool sock_test_tcpulp(const char * const remoteaddr,
>> + const char * const port)
>> +{
>> +
>> + struct addrinfo hints = {
>> + .ai_protocol = IPPROTO_TCP,
>> + .ai_socktype = SOCK_STREAM,
>> + };
>> + struct addrinfo *a, *addr;
>> + int sock = -1, ret = 0;
>> + bool test_pass = false;
>> +
>> + hints.ai_family = AF_INET;
>> +
>> + xgetaddrinfo(remoteaddr, port, &hints, &addr);
>> + for (a = addr; a; a = a->ai_next) {
>> + sock = socket(a->ai_family, a->ai_socktype, IPPROTO_TCP);
>> + if (sock < 0) {
>> + perror("socket");
>
> Why could we have an error here? It is just to avoid error message in
> the output for something we don't consider as an error.
It can fail e.g. due to memory pressure, or ulimits. Should never
happen in normal circumstances, but I think it's better to catch this
up, as this patch does.
Sorry, I should have added my comment at the next line. My question was
also: should we not "break" here in case of error?
But if should never fail, I guess we can still go to the next address.
As long as we don't have "useless" error messages each time we execute
the tests, I am then fine with both "break" and "continue" here.
>> + continue;
>> + }
>> +
>> + ret = setsockopt(sock, IPPROTO_TCP, TCP_ULP, "mptcp",
>> + sizeof("mptcp"));
>> + close(sock);
>> + if (ret == -1) {
>
> Should we check errno as well? Just to be sure we are not "blocked" for
> another reason.
I agree additionally checking errno == -EOPNOTSUPP would be better.
Otherwise LGTM.
In the longer run we may consider moving this test and ev. diag, MIB,
etc to a separate, functional-test binary/script, but I think this is
good for now.
Good idea, I was thinking about the same thing yesterday. I can have a
look at this in the future if needed.
Cheers,
Matt
--
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium