freebsd-dev/tools/regression/sockets/unix_cmsg
Maxim Sobolev 339efd75a4 Add a new socket option SO_TS_CLOCK to pick from several different clock
sources to return timestamps when SO_TIMESTAMP is enabled. Two additional
clock sources are:

o nanosecond resolution realtime clock (equivalent of CLOCK_REALTIME);
o nanosecond resolution monotonic clock (equivalent of CLOCK_MONOTONIC).

In addition to this, this option provides unified interface to get bintime
(equivalent of using SO_BINTIME), except it also supported with IPv6 where
SO_BINTIME has never been supported. The long term plan is to depreciate
SO_BINTIME and move everything to using SO_TS_CLOCK.

Idea for this enhancement has been briefly discussed on the Net session
during dev summit in Ottawa last June and the general input was positive.

This change is believed to benefit network benchmarks/profiling as well
as other scenarios where precise time of arrival measurement is necessary.

There are two regression test cases as part of this commit: one extends unix
domain test code (unix_cmsg) to test new SCM_XXX types and another one
implementis totally new test case which exchanges UDP packets between two
processes using both conventional methods (i.e. calling clock_gettime(2)
before recv(2) and after send(2)), as well as using setsockopt()+recv() in
receive path. The resulting delays are checked for sanity for all supported
clock types.

Reviewed by:    adrian, gnn
Differential Revision:  https://reviews.freebsd.org/D9171
2017-01-16 17:46:38 +00:00
..
Makefile Add a new socket option SO_TS_CLOCK to pick from several different clock 2017-01-16 17:46:38 +00:00
README
t_cmsg_len.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_cmsg_len.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_cmsgcred_sockcred.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_cmsgcred_sockcred.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_cmsgcred.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_cmsgcred.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_generic.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_generic.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_peercred.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_peercred.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_sockcred.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_sockcred.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
t_xxxtime.c.in Check that SCM_XXX timestamp returned by the kernel is less 1 second 2016-12-09 22:13:00 +00:00
t_xxxtime.h.in Auto-generate 2 test cases that differ only in structure and SCM_XXX constant 2016-12-06 18:22:25 +00:00
uc_check_time.c Check that SCM_XXX timestamp returned by the kernel is less 1 second 2016-12-09 22:13:00 +00:00
uc_check_time.h Check that SCM_XXX timestamp returned by the kernel is less 1 second 2016-12-09 22:13:00 +00:00
uc_common.c Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
uc_common.h Refactor the regression test code by splitting huge monolithic C 2016-12-05 17:21:04 +00:00
unix_cmsg.c Add a new socket option SO_TS_CLOCK to pick from several different clock 2017-01-16 17:46:38 +00:00
unix_cmsg.t

$FreeBSD$

About unix_cmsg
===============

This program is a collection of regression tests for ancillary data
(control information) for PF_LOCAL sockets (local domain or Unix domain
sockets).  There are tests for stream and datagram sockets.

Usually each test does following steps: creates Server, forks Client,
Client sends something to Server, Server verifies whether everything is
correct in received message(s).

It is better to change the owner of unix_cmsg to some safe user
(eg. nobody:nogroup) and set SUID and SGID bits, else some tests that
check credentials can give correct results for wrong implementation.

It is better to run this program by a user that belongs to more
than 16 groups.

Available options
=================

usage: unix_cmsg [-dh] [-n num] [-s size] [-t type] [-z value] [testno]

 Options are:
  -d            Output debugging information
  -h            Output the help message and exit
  -n num        Number of messages to send
  -s size       Specify size of data for IPC
  -t type       Specify socket type (stream, dgram) for tests
  -z value      Do not send data in a message (bit 0x1), do not send
                data array associated with a cmsghdr structure (bit 0x2)
  testno        Run one test by its number (require the -t option)

Description
===========

If Client sends something to Server, then it sends 5 messages by default.
Number of messages can be changed in the -n command line option.  Number
of messages will be given as N in the following descriptions.

If Client sends something to Server, then it sends some data (few bytes)
in each message by default.  The size of this data can be changed by the -s
command line option.  The "-s 0" command line option means, that Client will
send zero bytes represented by { NULL, 0 } value of struct iovec{}, referenced
by the msg_iov field from struct msghdr{}.  The "-z 1" or "-z 3" command line
option means, that Client will send zero bytes represented by the NULL value
in the msg_iov field from struct msghdr{}.

If Client sends some ancillary data object, then this ancillary data object
always has associated data array by default.  The "-z 2" or "-z 3" option
means, that Client will not send associated data array if possible.

For SOCK_STREAM sockets:
-----------------------

 1: Sending, receiving cmsgcred

    Client connects to Server and sends N messages with SCM_CREDS ancillary
    data object.  Server should receive N messages, each message should
    have SCM_CREDS ancillary data object followed by struct cmsgcred{}.

 2: Receiving sockcred (listening socket)

    Server creates a listening stream socket and sets the LOCAL_CREDS
    socket option for it.  Client connects to Server two times, each time
    it sends N messages.  Server accepts two connections and receives N
    messages from each connection.  The first message from each connection
    should have SCM_CREDS ancillary data object followed by struct sockcred{},
    next messages from the same connection should not have ancillary data.

 3: Receiving sockcred (accepted socket)

    Client connects to Server.  Server accepts connection and sets the
    LOCAL_CREDS socket option for just accepted socket.  Client sends N
    messages to Server.  Server should receive N messages, the first
    message should have SCM_CREDS ancillary data object followed by
    struct sockcred{}, next messages should not have ancillary data.

 4: Sending cmsgcred, receiving sockcred

    Server creates a listening stream socket and sets the LOCAL_CREDS
    socket  option for it.  Client connects to Server and sends N messages
    with SCM_CREDS ancillary data object.  Server should receive N messages,
    the first message should have SCM_CREDS ancillary data object followed
    by struct sockcred{}, each of next messages should have SCM_CREDS
    ancillary data object followed by struct cmsgcred{}.

 5: Sending, receiving timeval

    Client connects to Server and sends message with SCM_TIMESTAMP ancillary
    data object.  Server should receive one message with SCM_TIMESTAMP
    ancillary data object followed by struct timeval{}.

 6: Sending, receiving bintime

    Client connects to Server and sends message with SCM_BINTIME ancillary
    data object.  Server should receive one message with SCM_BINTIME
    ancillary data object followed by struct bintime{}.

 7: Checking cmsghdr.cmsg_len

    Client connects to Server and tries to send several messages with
    SCM_CREDS ancillary data object that has wrong cmsg_len field in its
    struct cmsghdr{}.  All these attempts should fail, since cmsg_len
    in all requests is less than CMSG_LEN(0).

 8: Check LOCAL_PEERCRED socket option

    This test does not use ancillary data, but can be implemented here.
    Client connects to Server.  Both Client and Server verify that
    credentials of the peer are correct using LOCAL_PEERCRED socket option.

For SOCK_DGRAM sockets:
----------------------

 1: Sending, receiving cmsgcred

    Client connects to Server and sends N messages with SCM_CREDS ancillary
    data object.  Server should receive N messages, each message should
    have SCM_CREDS ancillary data object followed by struct cmsgcred{}.

 2: Receiving sockcred

    Server creates datagram socket and sets the LOCAL_CREDS socket option
    for it.  Client sends N messages to Server.  Server should receive N
    messages, each message should have SCM_CREDS ancillary data object
    followed by struct sockcred{}.

 3: Sending cmsgcred, receiving sockcred

    Server creates datagram socket and sets the LOCAL_CREDS socket option
    for it.  Client sends N messages with SCM_CREDS ancillary data object
    to Server.  Server should receive N messages, the first message should
    have SCM_CREDS ancillary data object followed by struct sockcred{},
    each of next messages should have SCM_CREDS ancillary data object
    followed by struct cmsgcred{}.

 4: Sending, receiving timeval

    Client sends one message with SCM_TIMESTAMP ancillary data object
    to Server.  Server should receive one message with SCM_TIMESTAMP
    ancillary data object followed by struct timeval{}.

 5: Sending, receiving bintime

    Client sends one message with SCM_BINTIME ancillary data object
    to Server.  Server should receive one message with SCM_BINTIME
    ancillary data object followed by struct bintime{}.

 6: Checking cmsghdr.cmsg_len

    Client tries to send Server several messages with SCM_CREDS ancillary
    data object that has wrong cmsg_len field in its struct cmsghdr{}.
    All these attempts should fail, since cmsg_len in all requests is less
    than CMSG_LEN(0).

- Andrey Simonenko
andreysimonenko@users.sourceforge.net